C Programming Multiple Choice Question - Memory Alloction
This section focuses on the "Memory Alloction" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. What is the return type of malloc() or calloc()?
Explanation: malloc() and calloc() return void *, without void * we may get warning in C if we don't type cast the return type to appropriate pointer.
2. Which function is used to delete the allocated memory space?
Explanation: free() is used to free the memory spaces allocated by malloc() and calloc().
3.Among 4 header files, which should be included to use the memory allocation functions like malloc(), calloc(), realloc() and free()?
Explanation: #include<stdlib.h> is a header filer, which contains the inbuilt functions for all memory allocation functions.
4. Which of the following is/are true
5. Which of the following is true?
Explanation:The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime(execution of the program) from heap segment.
6. Which languages necessarily need heap allocation in the run time environment?
Explanation:Heap allocation is needed for dynamic data structures like tree, linked list, etc.
7. Which of the following statement is correct prototype of the malloc() function in c ?
Explanation: By defalut for malloc() function return type is void.
8. Specify the 2 library functions to dynamically allocate memory?
Explanation:2 library functions to dynamically allocate memory is malloc() and calloc().
9. malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's.
Explanation:malloc() and calloc() return void pointer for using a particular data type we made explicite type casting.
10.malloc() allocates memory from the heap and not from the stack.
Explanation:Heap area consist of hash codes .i.e. addreses while stack may or may not be that's why malloc() allocates memory from the heap.
Also check :