I recently started studying c++. Can you please explain me the output of the following program, it is not clear for me how it works. I know that at ++a at first 1 is added and then a is used, where as at a++ is the other way around. However the next output is confusing.
int main()
{
int a = 0;
cout << a << " " << a++ << " " << ++a << " " << a << "\n"; // 2 1 2 2
//cout << a << " " << ++a << " " << a++ << "\n"; // 2 2 0
//cout << a++ << " " << a << "\n"; // 0 1
}
Output 2 1 2 2