Difference between malloc and calloc
malloc()
|
calloc()
|
|||||||
malloc allocate the memory at
runtime
|
calloc allocate the memory at runtime
|
|||||||
The name
calloc stands for contiguous allocation. |
||||||||
malloc() initializes the allocated memory with garbage
values.
|
calloc() initializes the allocated memory with 0 value.
|
|||||||
Syntax :
int *
ptr = (casttype *) malloc(n * sizeof(int));
|
Syntax:
int * ptr = (casttype *) calloc(n, sizeof(int));
|
|||||||
Ex:
int n=5;
10bytes
|
Ex:
int n=5;
2bytes 2bytes
2bytes 2bytes 2bytes
|
|||||||
The malloc() function allocate single block of
memory
|
No comments:
Post a Comment