int n=3 ; n=++n + ++n; outputs n=10 But how ? In my pov it is like this, -You first set ’n’ equal to 3. You pre-increment it (increment it BEFORE you use it) - so now it’s 4. Then you pre-increment it again - so now it’s 5. Then you set n to n+n an...

Markdown supported · ⌘↵ to post
Luke Li
Programmer
This is undefined behavior in C++ and you should never write code like this, and do not bother to make sense of the compiler's output, it's a waste of time.
It boils down to "unsequenced multiple modifications" to the same memory location
n, i.e. they can happen in any order.P.S. Always add
-Wallwhen compiling with gcc.