#include <stdio.h>
int main(void)
{
int i;
int *p = (int *) malloc(5 * sizeof(int));
for (i=0; i<10; i++)
*(p + i) = i;
printf("%d ", *p++);
return 0;
}
So, I ran this code. Now I was told here that Why won't the output be 4 in this case? (in accepted answer) that *p++
will increment pointer first and then dereference it. Therefore, in the above code, shouldn't the pointer be incremented first and then de-referenced and hence output should be 1
? Instead, output comes out to be 0
. Why?