I am learning C language and now I am confused with the output of the below snippet.
#include <stdio.h>
int main(void) {
int p = 20;
printf("%d\n",++p + p++);
return 0;
}
How is the output of this 43
?
As far as I have understood, it should be evaluating as below:
++p
makes it 21.p++
, makes it 22 but will be21
during addition since it is post-increment.
So the expected output should be 21 + 21 = 42
. Isn't it?