+ 1
Why is the answer 1010?
#include <iostream> using namespace std; int main() { int i,j; j=10; i=(j++,j+100,999+j); cout<<i; return 0; }
3 Respostas
+ 4
If you put several expressions into parentheses like this, only the last one will be stored in the variable.
So i will be 999+j.
j+100 is just a value and has no effect.
j++ on the other hand has an effect - it changes the variable j to 11.
11 + 999 is 1010.
I wonder if this would be the case in every situation - it looks like undefined behavior to me.
But to be sure, let me call in ~ swim ~. 🙂
+ 2
Do you have any question about this?