increment operator

initially a=0,++a increments a to 1 and --a decrements it to 0 so x will be equal to zero..according to me the output should be 1,1,0 howevr the ans is 2,0,0

1
2
3
4
5
6
7
8
9
10
#include<iostream>
using namespace std;
int main()
{
int a=0,x;
x = ++a * --a;
cout<<++a<<endl<<a++ <<endl<< x <<endl;
}

Last edited on
Lines 6 and 7 are undefined, the output is arbitrary.

There's a summary of the relevant rules at http://en.cppreference.com/w/cpp/language/eval_order
Topic archived. No new replies allowed.