0
How was increment equal to decrement here??
In this code: int main() { int x=5,y=10,sum; x-- ; sum=x+y; cout<<sum<<"\n"; cout<<x<<"\n"; //How come final result as 14 not 15? return 0; How come 14 not 15?
3 ответов
+ 1
x-- is equivalent to x = x - 1; so after that statement x becomes 4.
+ 1
You can just testing x value before displaying sum value with cout then you can understand why.
x--;
cout<<x<<endl;
sum = x+y;
cout<<sum<<"\n";
0
You decrement x and then you add x to sum, if you want sum to be 15, you have to do "sum = x + y" before "x--".