+ 3
Can anyone explain the output of this program
int x=0, a, z; a = x++; z = ++a+x--; cout<<z;
4 odpowiedzi
+ 2
After x++ when i write x-- what is the value of x?
+ 1
answer is 2 only because when
a=x++;(a=0,x=1)
/*when u execute this,
Z=++a+x--; a value get incremented (a=1) ,when it comes to x-- x value doesn't get decremented (x=1)
so Z =(1)+(1)=2 */
0
@sidrath so according to u ans is 1? According to my calculations it is 1. But ans showing 2. I clearly understand in last operating a become 1 due to pre increment. But how x-- become 1. After x++ x become 1. But after x-- how it becomes 1
0
But the ans is 2. I also put 1 but it show wrong ans. So as ++a become 1 so x-- hv to be 1 to make two