C | Advanced Pointer | Question 9

Last Updated :
Discuss
Comments
C
#include <stdio.h>
#include <stdlib.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);
}
Compiler Error
0 1 2 2 3
0 1 2 3 4
1 2 3 4 5
Tags:
Share your thoughts in the comments