+ 3

Can anyone explain the output of this program

int x=0, a, z; a = x++; z = ++a+x--; cout<<z;

17th Mar 2017, 6:52 AM
Shuvam Pal
Shuvam Pal - avatar
4 Respuestas
+ 2
After x++ when i write x-- what is the value of x?
17th Mar 2017, 7:21 AM
Shuvam Pal
Shuvam Pal - avatar
+ 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 */
17th Mar 2017, 11:16 AM
shridhar Naik
shridhar Naik - avatar
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
17th Mar 2017, 10:05 AM
Shuvam Pal
Shuvam Pal - avatar
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
17th Mar 2017, 10:08 AM
Shuvam Pal
Shuvam Pal - avatar