I thought I understand how postfix and prefix works until I encounter this
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
int a = 3, b = 3, c = 3;
cout << a + a++ << endl; // = 7 Okay, makes sense to me
cout << b + c++ << endl; // = 6 Now I'm confused
int x = 3, y = 3;
cout << (x++)*(x++)*(x++) << endl; // = 3*4*5 = 60 Okay I get it
cout << (++y)*(++y)*(++y) << endl; // = 5*5*6 = 150 Wait what ? But why... ?
// I thought it would be 4*5*6 or 6*6*6 or something
return 0;
}
Is there any logical explaination for this ? Or it's some kind of undefined behaviour ?