MCQs Answers

Memory Management Techniques (Static, Stack, and Heap) MCQs

1. Which of the following is true about static memory allocation?

A) Memory is allocated during program execution
B) Memory is allocated at compile-time and cannot be changed during execution
C) Memory is allocated for function calls at runtime
D) Memory is automatically managed by the operating system

Answer: B) Memory is allocated at compile-time and cannot be changed during execution


2. What is the main advantage of static memory allocation?

A) It allows dynamic resizing of memory
B) It is more flexible than stack memory allocation
C) It is faster because memory is allocated once at compile time
D) It reduces the risk of memory fragmentation

Answer: C) It is faster because memory is allocated once at compile time


3. Which of the following memory types is used for local variables and function calls in most programming languages?

A) Heap
B) Stack
C) Static memory
D) Virtual memory

Answer: B) Stack


4. Which memory management technique uses Last In, First Out (LIFO) order for memory allocation?

A) Static memory allocation
B) Stack memory allocation
C) Heap memory allocation
D) Dynamic memory allocation

Answer: B) Stack memory allocation


5. In stack memory, which of the following happens when a function call is made?

A) Memory is allocated on the heap
B) An activation record is pushed onto the stack
C) The memory allocated for global variables is reallocated
D) No memory is allocated until the function returns

Answer: B) An activation record is pushed onto the stack


6. Which of the following best describes the heap memory?

A) Memory is allocated at compile time and is fixed
B) Memory is dynamically allocated and deallocated at runtime
C) Memory is allocated for local variables
D) Memory is shared between multiple threads only

Answer: B) Memory is dynamically allocated and deallocated at runtime


7. Which of the following is a disadvantage of using heap memory?

A) Memory cannot be deallocated during runtime
B) Memory allocation is slower compared to stack memory
C) Memory is automatically managed without any programmer input
D) Memory cannot be shared between functions

Answer: B) Memory allocation is slower compared to stack memory


8. Which type of memory is most suitable for managing large data structures whose size is not known at compile time?

A) Static memory
B) Stack memory
C) Heap memory
D) Cache memory

Answer: C) Heap memory


9. Which of the following best explains stack overflow?

A) Memory allocated on the stack exceeds the available heap space
B) The stack exceeds its allocated memory due to excessive function calls
C) Stack memory is fragmented due to frequent memory allocations and deallocations
D) The operating system runs out of memory

Answer: B) The stack exceeds its allocated memory due to excessive function calls


10. What happens when a program finishes execution in terms of stack memory?

A) Stack memory is cleared and remains available for the next execution
B) The stack memory is locked and cannot be reused
C) Stack memory is automatically reclaimed by the operating system
D) The stack memory needs to be manually deallocated

Answer: C) Stack memory is automatically reclaimed by the operating system


11. Which of the following is true about dynamic memory allocation in heap memory?

A) It happens automatically when the program executes
B) It must be manually managed by the programmer using functions like malloc, free, etc.
C) Memory is pre-allocated during compile time
D) It can only be used for local variables

Answer: B) It must be manually managed by the programmer using functions like malloc, free, etc.


12. What is the main disadvantage of using static memory allocation?

A) Memory is allocated at runtime, which can cause delays
B) The size of the allocated memory cannot be changed after compile-time
C) It requires complex memory management
D) It is less efficient than heap memory

Answer: B) The size of the allocated memory cannot be changed after compile-time


13. What is stack memory commonly used for in a function call?

A) Storing global variables
B) Storing local variables and function parameters
C) Storing memory for large data structures
D) Storing information about the operating system

Answer: B) Storing local variables and function parameters


14. Which of the following memory types is typically used to store global variables?

A) Static memory
B) Stack memory
C) Heap memory
D) Virtual memory

Answer: A) Static memory


15. What is the primary advantage of using heap memory?

A) It is automatically managed by the system
B) It can grow and shrink dynamically during runtime
C) It is faster than stack memory
D) It is always more secure than stack memory

Answer: B) It can grow and shrink dynamically during runtime


16. Which of the following is true about memory management in the heap?

A) Memory is allocated for each function call and deallocated automatically
B) Memory management must be explicitly handled using commands like malloc and free
C) Memory is allocated and deallocated automatically by the operating system
D) Memory is static and cannot be changed at runtime

Answer: B) Memory management must be explicitly handled using commands like malloc and free


17. Which of the following best describes the role of the heap in memory management?

A) It stores function parameters and local variables
B) It stores static data that does not change during execution
C) It provides dynamically allocated memory for objects and data structures
D) It stores executable code for the program

Answer: C) It provides dynamically allocated memory for objects and data structures


18. Which type of memory management is more susceptible to memory leaks if not properly handled?

A) Static memory
B) Stack memory
C) Heap memory
D) Virtual memory

Answer: C) Heap memory


19. Which of the following is true about memory fragmentation in heap memory?

A) It causes memory to be allocated in large contiguous blocks
B) It results in inefficient memory usage due to small unused gaps between allocations
C) It does not affect memory allocation or deallocation
D) It is not a concern for dynamically allocated memory

Answer: B) It results in inefficient memory usage due to small unused gaps between allocations


20. What happens when a function call in a program exceeds the available stack space?

A) The program will crash due to stack overflow
B) The program will automatically allocate more stack memory
C) The program will switch to using heap memory
D) The function call will be skipped

Answer: A) The program will crash due to stack overflow

Exit mobile version