#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int *p1 = calloc(5, sizeof(int)); // allocate and zero out an array of 5 int
int *p2 = calloc(1, sizeof(int[5])); // allocate and zero out an array of 5 int
int *p3 = calloc(5, sizeof *p3); // allocate and zero out an array of 5 int
for (int i = 0; i < 5; i++)
printf("p1[%d] == %d\n", i, p1[i]);
for (int i = 0; i < 5; i++)
printf("p2[%d] == %d\n", i, p1[i]);
for (int i = 0; i < 5; i++)
printf("p3[%d] == %d\n", i, p1[i]);
free(p1);
free(p2);
free(p3);
return 0;
}
/*
run:
p1[0] == 0
p1[1] == 0
p1[2] == 0
p1[3] == 0
p1[4] == 0
p2[0] == 0
p2[1] == 0
p2[2] == 0
p2[3] == 0
p2[4] == 0
p3[0] == 0
p3[1] == 0
p3[2] == 0
p3[3] == 0
p3[4] == 0
*/