+ 18
How malloc() , calloc() , realloc() functions work
Could anyone explain me breafly how malloc(), calloc () & realloc() functions work with example plz.
6 Antworten
+ 18
malloc():- Allocate the memory block of requested size and returns a pointer to the first byte of block.
Prototype:- void *malloc(int);
The return type of malloc() is void while input is integer number which is the required number of bytes of a block.
We have to type cast it because its return type is a pointer to void.
For example:-
Int *p;
p=(int*)malloc(sizeof(int)); /* p points to the block allocated by malloc */
*p=20; */ store value 20 in block allocated*/
calloc():- Allocates the multiple memory blocks each of same size and also initialises all bytes to zero.
Prototype:-
void *calloc(int n, int size);
realloc():- Modifies the number of bytes required allocated memory block.
It is used to change the size of memory block allocated previously using malloc() or calloc() function.
Prototype:-
void *realloc(void *ptr, int size);
+ 11
Yamin Mansuri could u suggest me any resources for C from where u learn these concept
+ 11
👑Sam👑 youtube
0
هاي