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

closed Dec 27, 2021

answered Jun 19, 2019 by anonymous

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

commented Jun 21, 2019 by (100 points)
right ans is 6
commented Jun 26, 2019 by (110 points)
yaa right answer is 6 bcz first it will make a = 3 bcz of preincrimnet and the it will add 3 to 3 as a++ is post increment so it's answer will be 6
commented Jun 27, 2019 by anonymous
commented Jul 1, 2019 by gowtham
first a is incremented by one because that ++a first interment then stored a++ is first stored then is incremented.so 2 incremented 3 now a value is 3 then a++ first stored 3 does not incremented so 3+3=6.
commented Jul 3, 2019 by (100 points)
the answer is 7 because when u code this the answer is shown as 7, this is because the first incrimination (++a) is 3 then the second one becomes 4 as a=3 for the second incrimination so it becomes 3+4=7
commented Jul 4, 2019 by anonymous
3+3=6
A= 4 AFTER EXECUTION
commented Dec 22, 2019 by (560 points)
no the out put will be a garbage value
commented Jan 24, 2020 by (100 points)
It will be the 7.
commented Dec 26, 2021 by (89,230 points)
The expression is not a legal C expression as the C standard does not specify in what order this needs to be executed, hence the evaluation depends on the compiler itself. Just try the GNU C, Turbo C or Microsoft C and you can see the result differs for the same code.

Hence the answer is: UNDEFINED BEHAVIOUR
commented May 30, 2023 by (100 points)
a = 2
a++ = 3
++a = 3

++a + a++ = 6

–1 vote
answered Jun 20, 2019 by anonymous
answered Jun 20, 2019 by anonymous
answered Jun 20, 2019 by (140 points)
–1 vote
5

++a define a=a+1, So it's value is a=3

a++ define only a+1 but it noe store into a so value of a is 2

so 3+2=5

commented Jun 21, 2019 by anonymous
Sorry to say but you are wrong.
Value of a is 2 at first
For ++a, the value of a is icremented by 1 immediately,so it becomes a=2+1=3
++a=3
So, the new value of a is 3 now
the trickiest part now ---------
therefore, (++a)+(a++) = 3 + 4 = 7
so 7 will be the answer
–1 vote
answered Jun 22, 2019 by (120 points)
output of this is 5
–1 vote
answered Jun 22, 2019 by (160 points)
Output for this is 7

a has value 2 the it get incremented as 3 add to the post incremented value 4 then the answer is absolutely 7.
–1 vote
answered Jun 22, 2019 by (120 points)
initially pre-increment operation occurs, ++a=3, then substiution of the values takes place,i.e (++a + a++)=(3 + 3) =6 then post increment occurs hence a becomes 7

the ans is 7
–1 vote
answered Jun 25, 2019 by Harshit 1 flag