C examples for Memory:calloc
Use calloc() allocate memory
#include <stdlib.h> #include <stdio.h> int main( void ) { unsigned long num; int *ptr;//from w w w.j a v a2 s.c o m printf("Enter the number of type int to allocate: "); scanf("%ld", &num); ptr = (int*)calloc(num, sizeof(long long)); if (ptr != NULL) puts("Memory allocation was successful."); else puts("Memory allocation failed."); return 0; }