Calloc& Malloc
Calloc& Malloc
Allocation of memory at the time of execution is called dynamic memory allocation. It is done using the standard
malloc(): used to allocate required number of bytes in memory at runtime. It takes one argument, viz. size in
bytes to be allocated.
Syntax:
Example:
a = (int*) malloc(4);
calloc(): used to allocate required number of bytes in memory at runtime. It needs two arguments
vi
1/3
z.,
Syntax:
Example:
Here sizeof indicates the size of the data type and 8 indicates that we want to reserve space for storing 8
integers.
Difference is.
2/3
2. By default, memory allocated by malloc() contains garbage values. Whereas memory allocated by calloc() contains all zeros.
3/3