+ 18

How malloc() , calloc() , realloc() functions work

Could anyone explain me breafly how malloc(), calloc () & realloc() functions work with example plz.

1st May 2019, 3:56 PM
Mohd Abdul Sameer
Mohd Abdul Sameer - avatar
5 ответов
+ 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);
1st May 2019, 4:20 PM
Yamin Mansuri
Yamin Mansuri - avatar
+ 11
Yamin Mansuri could u suggest me any resources for C from where u learn these concept
2nd May 2019, 3:50 AM
Mohd Abdul Sameer
Mohd Abdul Sameer - avatar
+ 11
👑Sam👑 youtube
2nd May 2019, 4:13 AM
Yamin Mansuri
Yamin Mansuri - avatar
0
هاي
2nd May 2019, 5:25 PM
نبع الوفاء
نبع الوفاء - avatar