# int a=2; printf("%d", ++a + a++);

closed Dec 27, 2021

–1 vote
answered Jun 27, 2019 by (120 points)
THE RESULT OF THE GIVEN QUESTION IS 6
–1 vote
answered Jun 27, 2019 by anonymous

I tested in the online C compiler.
The result printed was 7.

int a=2; printf("%d", ++a + a++);

The explanation is that

++a:    uses the incremented value of "a" AND increments the value of "a" in one step

a++:  uses the incremented value of "a" .   After the expression is evaluated and assigned, it THEN increments a

So in order of what happens
"++a"    "+"   "a++"

a starts at 2

the expression increments a and sets a to that increment. so the first term "++a" has been evaluated to 3, also  a=3 now
3   "+"   "a++"

now we plug 3 into a

3 "+" "3++" which is
3 "+" "4"
since that is the end of the expression, it returns the value 3+4 = 7, to the print function.

then it changes a to 4. (by incrementation)

would result in 11 at the end.

the difference is after a++, there is more expression(s) to be evaluated.

so before it goes to the next expression, it sets a to 4.

so we have the 7 from before, and its added by an a.  and since the a = 4, we have 7+4 = 11

–1 vote
answered Jun 28, 2019 by anonymous
the ans is 6
–1 vote
answered Jun 29, 2019 by anonymous
–1 vote
answered Jun 30, 2019 by anonymous
–1 vote
answered Jul 1, 2019 by anonymous
in the question operation is executed from left to right

i.e; 1) ++a is executed (++a=3)

2) a++ is executed ,here increment is done but not stored so (a++=3)

ans=6
–1 vote
answered Jul 1, 2019 by (120 points)

At first preincriment operation is done then value of a is 3. now the value of A is 3 . when postincriment operation is performed then its value is 4.Finally sum of these two is 7.

–1 vote
answered Jul 2, 2019 by pallavi
–1 vote
answered Jul 2, 2019 by (120 points)
++a=3 a++ remains 3 only. So ++a+a++=6
–1 vote
answered Jul 3, 2019 by anonymous

++a it will not take any increment.

a++ is equals to a+1.

2+(2+1)=5