Pick out the odd one out of the following malloc(), calloc(), free(), realloc() ?
- free()
Explanation:
- Here malloc(), calloc(), realloc() are the memory allocation function. whereas free() is used to free the memory which is allocated by the above function.
- so the free() is odd term.
malloc()
- The function malloc() reserves a block of memory of specified size and return a pointer of type void which can be casted into pointer of any form.
- It allocates single block of memory
calloc()
- calloc() allocates multiple blocks of memory each of same size and sets all bytes to zero.
- It allocates space for an array elements, initializes to zero and then returns a pointer to memory.
realloc()
- If suppose we assigned more or less memory than required, then we can change the size of the previously assigned memory space using realloc.
free()
- The function free is used to deallocate or free the memory after the program finishes which was dynamically allocated in the program.