Consider this piece of code
int j = 0;
int x = 0;
for(int i=0;i<5;i++){
j = x++;
cout<<x<<" ";
}
Output:
1 2 3 4 5
Now consider this
int j=0;
for(int i=0;i<5;i++){
j = j++;
cout<<j<<" ";
}
Output:
0 0 0 0 0
My doubt is why is j
not being incremented after it is assigned the value 0
. Isn't j=j++;
equivalent to j = j;
j++;
and if it isn't then what's going on with the first case. I know it's a silly doubt but I couldn't figure this out by myself.