calloc() - Dynamic Allocation Function
How is calloc() used in C++?
is used to allocate the memory, which will be equal to the value, "num*size". Function returns a pointer to the first byte of the allocated space.If there is no space to allocate, a "NULL" pointer is returned.
void *calloc(size_t num, size_t);
printf("Enter the number to allocate: ");
ptr = (int*)calloc(num, sizeof(int));
if (ptr != NULL)
puts("Memory allocation was successful.");
Enter the number to allocate: 1000
Memory allocation was successful
In the above Dynamic allocation function example the number parameter for the "calloc()" is got as input. Once the memory is allocated a message is displayed.