Possible Duplicates:
What is more efficient i++ or ++i?
How do we explain the result of the expression (++x)+(++x)+(++x)?
Difference between i++ and ++i in a loop?
I am trying these two programs:
void fun(){
int k = 0;
int i= 10;
k = (i++)+(++i);
cout << k << endl;
}
Output = 22 as i++ will give 10 and ++i will evaluate into 12.
But
void fun(){
int k = 0;
int i = 10;
k = (++i)+(++i);
cout << k << endl;
}
Output = 24
It should be 23 I guess, or is there something that I am not able to see?