+ 1
Solve this
a=10 x=++a + --a + a++ + ++a + a++ x=?
7 Answers
+ 5
IDE ought to be showing "undefined behaviour, multiple read access and modification without sequence point".
In the translation of C to ASM, the order of events is only up to sequence points in the code. Between sequence points, the compiler is free to arrange the ASM instructions anyway it sees fit to optimise for speed or size. Since you operate on `a` 5 times without sequence point (points where C and ASM are sync'ed again), there is no telling what the result is.
If you want to know why your compiler in its current version for your OS evaluates this expression to 54, find the switch to compile without assembling (usually the -S switch) and study the assembler code.
+ 2
But IDE(dev c) showing answer 54
+ 1
line 1,
a is not defined;
Try it yourself.
If done see the answer below
1 + 0 + 0 + 2 + 2
if a = 0;
then,
Ans: 5 , a = 3
+ 1
The order of operations is:
1. Unary (++, --)
2. Binary (+)
Furthermore, when there is "a++" the old value of "a" is taken for the expression and then gets incremented and worked with in the next steps.
That's how we get
a=10
a = 11 (incremented first, then taken)
+ 10 (decremented first)
+ 10 (10 is taken, new value is 11)
+ 12 (11 is increased first, then taken)
+ 12 (we take 12 for the expression and then it's set to 13, but that value remains unused)
= 55
+ 1
Himanshu Sharma You may also got some Warnings variable "a" may not defined
See the following code , you may understand
https://code.sololearn.com/c0mMgL7kdmM4/?ref=app
0
11 + 10 + 10 + 12 + 12
Ans. 55 and a= 13
0
x = 55, a =13