Here is a simple code to evaulate an arithmetic expression :
a=(++a)+(++a)+(a++)+(a++) where a is an integer . Taking an initial value of a=10,we have,
a= (++10)+(++a)+(a++)+(a++)
= 11+(++11)+(a++)+(a++)
= 11+12 +(12++)+(a++)
= 11+12+12+(13++)
= 11+12+12+13
a= 48
A simple Code executed using Turbo C++3.0 on Windows OS gives an output of 50 for the same.
CODE:
As already said when this code is executed the value of a is printed as 50.Code:#include<stdio.h> void main() { int a=10; a=(++a)+(++a)+(a++)+(a++); printf("%d",a); }
Thus i am most certain that i have gone wrong in evaluating the expression myself as i have got 48 as the answer. Can anybody identify this error and tell me how this expression gets evaulated?
Thanks in advance.