I tried the following code in my Turbo C++ ..
int j=5; cout<<++j + ++j + j++;
and got the result 20, as expected.
But, when I replaced the code and assigned the same to another variable x, it gives result 21.
int j=5,x; x= ++j + ++j + j++; cout<<x;
gives 21 against the expected value, 20
if I assign it to same variable j, by replacing x
int j=5; j=++j + ++j + j++; cout<<j;
It gives 22 as the output.
Can anyone help please? I am a Computer Science teacher and need urgent help...!
Edited 6 Years Ago by Nick Evan: Added code-tags