0
Why are post-fix and pre-fix code and syntax in c++ not producing the intended output?
Why is the output of this code: https://code.sololearn.com/cSo0xc6skXfG/?ref=app #include<iostream> using namespace std; int main() { int x = 0; int y = 0; y = ++++x+x++; cout << y << endl; cout << x << endl; return 0; } 5 3 Shouldn't it be: 4 3 Please help!
3 Respostas
+ 3
((++(++x)) +(x++)) and also
See the warning about sequence point..
Result is undefined by standards so
Output is different in different compilers......
https://en.m.wikipedia.org/wiki/Sequence_point
Edit:
See in this, @swim given explanation for almost similar example ++a + ++a
https://www.sololearn.com/Discuss/2038766/?ref=app
+ 1
i think because x++ itself will call ++x before returning rvalue, so the first x will increment 3 times
+ 1
Thanks guys...
I appreciate your help :)