0
How to solve this problem?
Int a=5; int b; b= a++ + ++a; what is the value of b?
3 Réponses
+ 2
this is actually an undefined behavior, not even defined in the latest C++ standard, so it will depend on the implementation if and how it works
+ 2
True. That's why it's best to write good code. Good code is more likely to be future proof, if weird hacks are avoided. It's an interesting question though.
+ 1
It does the a+a first, then does the ++ twice:
i.e. a+a = 10, then the two increments are performed, giving the answer of 12:
Source:
http://www.cplusplus.com/forum/beginner/26383/
Code to demonstrate:
https://code.sololearn.com/c4tCJ8KvqIIj/#c