1 // Stores an array of numbers in heap, then prints it on 2 // stdout finally frees the memory used; 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 #define ARR_LEN 10 8 9 int main (void) 10 { 11 int *p; 12 13 if((p = (int*)malloc(ARR_LEN * sizeof(int))) == NULL) 14 return 1; 15 16 for(int i = 0; i < ARR_LEN; i++) { 17 *(p + i) = i; 18 printf("%d\n", *(p + i)); 19 } 20 free(p); 21 return 0; 22 }