+ 1
Guys what will be the value of x if m=10 and x=++m + m++ ? Explain also ?
6 Answers
+ 6
in java its 22 but im curious why its not 23
how i see it is
++m increments the value of m so now m=11
m++ uses the new value of m = 11
so ++m + m++ = 22 here
but then m++ should increment by one giving the value of 23.
+ 6
Wouldn't that be another case of undefined behavior in C(++)? I think some compilers might evaluate the expression to 22 and others to 23 because you can't tell the order in which the expression will be evaluated and whether the increment by m++ takes place before or after the result is assigned to x.
+ 2
Well in JavaScript it shows 22 but in c or c++ it's 23.
+ 1
Interesting!!!
0
Yeah that's what i was thinking.