Memory Management in data structures MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is the primary purpose of memory management in data structures?
A) To store data permanently
B) To efficiently allocate and deallocate memory
C) To increase processing speed
D) To compress data
Answer: B) To efficiently allocate and deallocate memory

Which of the following is a type of memory allocation?
A) Static allocation
B) Dynamic allocation
C) Both A and B
D) None of the above
Answer: C) Both A and B

What is static memory allocation?
A) Memory is allocated at runtime
B) Memory is allocated at compile time
C) Memory is allocated using pointers
D) Memory is allocated in heap
Answer: B) Memory is allocated at compile time

What is dynamic memory allocation?
A) Memory is allocated before the program starts
B) Memory is allocated during program execution
C) Memory is never freed
D) Memory is allocated using fixed sizes
Answer: B) Memory is allocated during program execution

Which function is used to allocate memory dynamically in C?
A) malloc()
B) alloc()
C) new
D) reserve()
Answer: A) malloc()

What happens if memory allocated using malloc() is not freed?
A) Memory leak occurs
B) The program runs faster
C) No effect
D) The program terminates
Answer: A) Memory leak occurs

Which function is used to deallocate memory in C?
A) free()
B) delete
C) release()
D) dealloc()
Answer: A) free()

What is a memory leak?
A) Memory used by the program is freed
B) Memory allocated but not released
C) Memory allocated at compile time
D) Memory used for global variables
Answer: B) Memory allocated but not released

Which of the following is a disadvantage of dynamic memory allocation?
A) Flexibility
B) Fragmentation
C) Easy to implement
D) Efficient memory usage
Answer: B) Fragmentation

What is fragmentation in memory management?
A) Allocation of memory in large blocks
B) Inefficient use of memory due to allocation and deallocation
C) Memory being accessed by multiple programs
D) None of the above
Answer: B) Inefficient use of memory due to allocation and deallocation

What is the purpose of the ‘sizeof’ operator in C/C++?
A) To determine the size of a variable in bytes
B) To allocate memory dynamically
C) To free allocated memory
D) To copy data from one variable to another
Answer: A) To determine the size of a variable in bytes

What is the difference between stack and heap memory?
A) Stack is used for static allocation, heap for dynamic
B) Stack is faster than heap
C) Stack memory is managed automatically, heap is manually managed
D) All of the above
Answer: D) All of the above

What type of memory allocation does the ‘new’ keyword perform in C++?
A) Static allocation
B) Dynamic allocation
C) Stack allocation
D) None of the above
Answer: B) Dynamic allocation

Which operator is used to deallocate memory allocated with ‘new’ in C++?
A) delete
B) free
C) dealloc
D) release
Answer: A) delete

What can cause a dangling pointer?
A) Allocating memory correctly
B) Freeing memory that is still in use
C) Using static memory
D) None of the above
Answer: B) Freeing memory that is still in use

Which of the following methods can help prevent memory leaks?
A) Using static memory only
B) Properly freeing all allocated memory
C) Allocating large chunks of memory
D) Using global variables
Answer: B) Properly freeing all allocated memory

In which scenario would you prefer dynamic memory allocation?
A) When the size of data is known at compile time
B) When data size may vary during execution
C) When you want to optimize execution time
D) When you want to minimize memory usage
Answer: B) When data size may vary during execution

What is the main advantage of using dynamic memory allocation?
A) Faster execution
B) Greater control over memory usage
C) No need for memory management
D) Simpler code
Answer: B) Greater control over memory usage

Which of the following is NOT a memory management technique?
A) Paging
B) Segmentation
C) Compiling
D) Fragmentation
Answer: C) Compiling

What is a memory pool?
A) A single large block of memory
B) A collection of fixed-size memory blocks
C) A way to allocate stack memory
D) A method to sort memory addresses
Answer: B) A collection of fixed-size memory blocks

What is the purpose of garbage collection?
A) To improve program execution speed
B) To automatically free unused memory
C) To allocate more memory
D) To manage static memory
Answer: B) To automatically free unused memory

What is the impact of not managing memory properly in a program?
A) Increased performance
B) Reduced memory consumption
C) Crashes and unpredictable behavior
D) Simplified code structure
Answer: C) Crashes and unpredictable behavior

In what situation would stack memory be preferred over heap memory?
A) When the size of data is unknown
B) When data needs to be persistent
C) When speed is critical and size is fixed
D) When data needs to be shared
Answer: C) When speed is critical and size is fixed

Which of the following is a common method to detect memory leaks?
A) Code reviews
B) Memory profiling tools
C) Reducing the number of variables
D) Using static memory
Answer: B) Memory profiling tools

What does the term ‘stack overflow’ refer to?
A) Excessive allocation of heap memory
B) The stack exceeding its size limit
C) Memory being allocated incorrectly
D) None of the above
Answer: B) The stack exceeding its size limit

What is a sentinel value in memory management?
A) A value that indicates the end of a data structure
B) A type of memory allocation
C) A pointer to a memory address
D) A method of freeing memory
Answer: A) A value that indicates the end of a data structure

What is the primary function of the operating system in memory management?
A) To allocate memory to running programs
B) To compile programs
C) To monitor program execution
D) To free unused memory
Answer: A) To allocate memory to running programs

How does segmentation differ from paging?
A) Segmentation is based on variable-size blocks, while paging is fixed-size
B) Segmentation is faster than paging
C) Paging uses less memory than segmentation
D) There is no difference
Answer: A) Segmentation is based on variable-size blocks, while paging is fixed-size

What is ‘thrashing’ in the context of memory management?
A) Excessive swapping of data between memory and disk
B) An efficient use of memory
C) An increase in memory speed
D) None of the above
Answer: A) Excessive swapping of data between memory and disk

What is an object in memory management?
A) A pointer to a memory address
B) A block of memory that has a specific type
C) A variable
D) None of the above
Answer: B) A block of memory that has a specific type

What is the main disadvantage of static memory allocation?
A) It is faster
B) It is less flexible
C) It requires more coding
D) It is not portable
Answer: B) It is less flexible

Which of the following best describes a heap?
A) A specific area of memory used for stack allocation
B) A memory area for dynamic allocation
C) A method of memory management
D) None of the above
Answer: B) A memory area for dynamic allocation

What are memory addresses?
A) Locations in the CPU
B) Locations in the RAM
C) The speed of memory
D) The data types of variables
Answer: B) Locations in the RAM

How can memory fragmentation be reduced?
A) By using dynamic allocation only
B) By using fixed-size memory blocks
C) By allocating all memory at once
D) By increasing memory size
Answer: B) By using fixed-size memory blocks

What does a pointer represent in memory management?
A) A variable
B) An address in memory
C) A type of allocation
D) A memory error
Answer: B) An address in memory

What type of memory is automatically managed by the compiler?
A) Heap memory
B) Stack memory
C) Global memory
D) Static memory
Answer: B) Stack memory

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs