I was casually coding when I wrote this C code:
#include <stdio.h>
int main()
{
int i;
i = 10;
printf("i : %d\n",i);
printf("sizeof(i++) is: %d\n",sizeof(i++));
printf("i : %d\n",i);
return 0;
}
And when I ran the code, the result I get is,
i : 10
sizeof(i++) is: 4
i : 10
I was baffled by this result as I expected i++ inside sizeof operator to have incremented i. But it seems not. So out of curiosity I wrote the following program:
#include <stdio.h>
int add(int i)
{
int a = i + 2;
return 4;
}
int main()
{
int i;
i = 10;
printf("i : %d\n",i);
printf("sizeof(i++) is: %d\n",add(i++));
printf("i : %d\n",i);
return 0;
}
for this program, the output is:
i : 10
sizeof(i++) is: 4
i : 11
Now I'm more and more baffled.
Sorry if this is a noob question (which I am) but I don't really understand even how to google for such a problem!
Why is the value of i different in these two programs? Please help!