Mega Code Archive

 
Categories / C / Code Snippets
 

Allocates sufficient memory for an array of num objects of size size

//Declaration: void *calloc(size_t num, size_t size); //Return: returns a pointer to the first byte of the allocated region. #include <stdlib.h> #include <stdio.h> int main(void){ float *j; j = calloc(100, sizeof(float)); if(!j) { printf("Allocation Error\n"); exit(1); } }