The site https://www.geeksforgeeks.org/difference-between-p-p-and-p/ says
Precedence of prefix ++ and * is same. Associativity of both is right to left.
Precedence of postfix ++ is higher than both * and prefix ++. Associativity of postfix ++ is left to right.
1st Code Sample:
int x[4] = {0, 1, 2, 3};
int *ptr = x;
cout << x[0] << " at " << &x[0] << "\n";
cout << x[1] << " at " << &x[1] << "\n";
cout << x[2] << " at " << &x[2] << "\n";
cout << x[3] << " at " << &x[3] << "\n";
cout << "*ptr = " << *ptr << " at " << ptr << "\n";
cout << "*++ptr = " << *++ptr << " at " << ptr << "\n";
cout << "++*ptr = " << ++*ptr << " at " << ptr << "\n";
cout << "*ptr++ = " << *ptr++ << " at " << ptr << "\n";
This produces the output:
0 at 0012FF1C
1 at 0012FF20
2 at 0012FF24
3 at 0012FF28
*ptr = 0 at 0012FF1C
*++ptr = 1 at 0012FF20
++*ptr = 2 at 0012FF20
*ptr++ = 2 at 0012FF24
In the last cout statement inspite of post increment pointer it first increments the pointer "ptr" value before being used.
2nd Code Sample:
int cd = 7;
cout << "cd = " << cd << " at " << &cd<< "\n";
cout << "++cd = " << ++cd << " at " << &cd << "\n";
cout << "cd++ = " << cd++ << " at " << &cd << "\n";
This procudes an output:
cd = 7 at 0012FF04
++cd = 8 at 0012FF04
cd++ = 8 at 0012FF04
In the last cout statement here note that cd incremented and then accessed inspite of using post increment operator.
3rd Code Sample:
int c = 10;
int d = 1;
cout << c << " at " << &c << "\n";
int e = c+++d;
cout << c << " at " << &c << "\n";
cout << d << " at " << &d << "\n";
cout << e << " at " << &e << "\n";
This gives the output:
10 at 0012FF04
11 at 0012FF04
1 at 0012FEF8
11 at 0012FEEC
We see that ++ increments vars value AFTER it is accessed in the statement.
Question is in the 3rd code sample unlike in first two code samples why post increment operator did not increase the value of variable "c" before accessing it? Why in the last code sample the variable did not received the value of 12?