Related Tags

What is Calloc in C?


The calloc() function in C is used to allocate a specified amount of memory and then initialize it to zero. The function returns a void pointer to this memory location, which can then be cast to the desired type. The function takes in two parameters that collectively specify the amount of memory ​​to be allocated.

Code​

Take a look at the code below. Note how (int*) is used to convert the void pointer to an​ int pointer.

#include<stdio.h>
#include<stdlib.h>

int main() {

    int* a = (int*) calloc(5, sizeof(int));

    return 0;
}
RELATED COURSES
View all Courses

Keep Exploring