+ 4
What will be the result of I=3; I=++I + I++; cout<<i
I thought it would be 7 but apparently not but why?
6 odpowiedzi
0
I has already been incremented by ++I by the time you reach I++, so the expression is 4 + 4. I++ then sets I to 5, and then I = 4 + 4 = 8 overwrites that change.
You won't find stuff like i = i++ anywhere but in programming exercises.
0
I=3
++I pre increment so I=4,
now expression is I= 4 + 4 (I++)= 8
since I++ post increment is there so I value which is result of expression is incrementEd by 1
now I =9, it is the output
0
9 is the output
0
This result only dev c++ compilers. Another compilers output 8.
0
++I da u 4ga teng bo'ladi. 4+I++ da 8 ga teng.
0
it's called "undefined behavior".What will happen?It all depends on your compiler, so different compiler different answer. There is no need to think too much about these problem.