what will be the result of ++m- --n+m++ if m=9 and n=5
Answers
Answer:
What will be the values of x, m, and n after execution of the following statements? Int x, m, n; m = 10; n = 15; x = ++m + n++.
Pursue your healthcare graduate degree online.
According to the theories in textbooks, answer for this expression would be 26.
Pre-increment (++m) is performed and is reflected immediately in the expression.
So, new value of m = 11.
Post-increment is performed but is not immediately reflected in the same expression, but in the lines immediately following it.
So, n = 15.
Therefore x = 11+15 =26.
If there is a line immediately following the given expression, for instance,
x = ++m + n++;
y = m+n;
Now, the value of y would be 11+16 = 27.
But, practically, this may fail in different compilers and result in undefined behaviour.
The above one will surely work in Turbo C/C++.