Why is the answer 1010? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

26th Jan 2020, 9:12 AM
Atharva Labhasetwar
2 Answers
+ 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 ~. 🙂
26th Jan 2020, 9:22 AM
HonFu
HonFu - avatar
+ 2
Do you have any question about this?
26th Jan 2020, 9:16 AM
HonFu
HonFu - avatar