int n = 1;
n = n++;
cout<<n<<endl;
output:1
I have searched it on Google. Analysis says that "n = n++" is:First assign n to n, then n add 1.
I don't know why it is giving output as 1, rather than 2.
int n = 1;
n = n++;
cout<<n<<endl;
output:1
I have searched it on Google. Analysis says that "n = n++" is:First assign n to n, then n add 1.
I don't know why it is giving output as 1, rather than 2.
This code is undefined behavior. The compiler can do anything, even make demons fly out of your nose if it feels like it. To find out more about this, you can read up at https://en.wikipedia.org/wiki/Sequence_point