What is syntax for malloc()and calloc()? | SoloLearn: Learn to code for FREE!


What is syntax for malloc()and calloc()?

4/25/2020 9:19:21 AM

Dhanasekar .L

1 Answer

New Answer


malloc: Parameters: Int, size of memory in bytes Returns: void *, pointer to void , need to be type casted into valid pointer for proper pointer arithmetic. calloc: Parameters: Int, size of each block in bytes, and Int, total number of blocks. Returns: same as malloc Example: int *arr = (int *)malloc(ELEMENT_COUNT * sizeof(int)); Read more : https://www.google.com/amp/s/www.geeksforgeeks.org/dynamic-memory-allocation-in-c-using-malloc-calloc-free-and-realloc/amp/