Before I explain anything,I would like you to run the following program.
void main()
{int j =10;
cout<<“j before increment =“<<j;
cout<<“++j =“<< ++j;
cout<<“ value of j after pre inc is “<<j;
cout<<“j++ = “<<j++;
cout<<“value of j after post inc is “<<j;
j=10;
cout<< “lets try results if all are cascaded in same line”; // compplied right to left
cout<< “j=“<<j<“++j=”<<++j<<“j++=”<<j++;
}
It is interesting to note the output:
Output
j before increment 10
++j =11
value of j after pre inc is 11
j++ = 11
value of j after post inc is 12
lets try results if all are cascaded in same line
j=12
++j= 12
j++= 10;
This is because the values are evaluted from right to left here and not left to right