I'm trying to understand prefix increment & postfix increment operator in C++(G++ 9.3, C++20 + GNU extensions). The code is:
#include<iostream>
using namespace std;
int main() {
int a=12,b=13,c;
c=a++ + ++a / 7 + b++;
cout<<a<<" "<<b<<" "<<c<<endl;
c=++a + a++ / 3 + ++b;
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
And, it's giving the following output:
14 14 27
16 15 36
But, I have tried to run the same code on Mac OS Monterey(clang - 1300.0.29.30). And it gives the following output:
14 14 27
16 15 35
Why both are not the same?
Aucun commentaire:
Enregistrer un commentaire