Consider the following program.
#include<iostream>
using namespace std;
void fn(int a, int b)
{
cout << a;
cout << b;
}
int main()
{
int a = 10;
fn(a++, --a);
fn(a--, ++a);
return 0;
}
I don't understand the output I get (gcc 11.2):
9101110
Shouldn't a++
be evaluated first? How can fn
then get a 9? Is this undefined behavior or simply "indeterminate"? Did C++17 change in this respect?
a++, --a
infn(a++, --a)
-- are not expressions). – Rocker