int main (void)
int * pdata;
printf ("Enter the size of the array: ");
fflush(stdout); /* Make sure the prompt gets printed to buffered stdout. */
if (1 != scanf("%zu", &n)) /* If zu is not supported (Windows?) use lu. */
fprintf("scanf() did not read a in proper value.\n");
pdata = calloc(n, sizeof *pdata);
if (NULL == pdata)
perror("calloc() failed"); /* Print error. */
free(pdata); /* Clean up. */
This program tries to scan in an unsigned integer value from standard input, allocate a block of memory for an array of n elements of type int by calling the calloc() function. The memory is initialized to all zeros by the latter.
In case of success the memory is releases by the call to free().