expression trees - Output of C program -
this question has answer here:
int a[]={10,20,30,40}; int x=0; int v=a[++x]+ ++x + a[--x]; printf("%d",v);
what output of program??
completely confused output. no way going done according operator precedence knowledge.
according me, in expression array subscripting [] has highest precendence , should executed first. both [] should executed first left right. in case value of x increment first, decrement , come 0. expression become int v=a[0] + ++x + a[0]
. pre increment having highest precedence , incremented 1. our expression become int v=a[0]+1+a[0]
. final output 21.
but not case. have checked on different compiler implementations , no 1 prints 21.
i surprised because value printed 43, no understandable me. that's why want me understand , come result 43.
the link others have suggested using increment , same rvalue , lvalue cases. different , not clear. tried contruct expression tree , solve 43 no in scope.
output of code:
int v=a[++x]+ ++x + a[--x];
is undefined , depends on compiler implementation.
Comments
Post a Comment