I came across the following code on geeksquiz.com but could not understand how the expressions involving prefix, postfix and dereference operators are evaluated in C:
#include <stdio.h>
#include <malloc.h>
int main(void)
{
int i;
int *ptr = (int *) malloc(5 * sizeof(int));
for (i=0; i<5; i++)
*(ptr + i) = i;
printf("%d ", *ptr++);
printf("%d ", (*ptr)++);
printf("%d ", *ptr);
printf("%d ", *++ptr);
printf("%d ", ++*ptr);
free(ptr);
return 0;
}
The output is given as :
0 1 2 2 3
Can somebody please explain how this is the output for the above code?