Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Multiple Choice Questions

Q321: What does the serviceCustomer function do with the pointer retrieved from the queue?
  • A: Prints the customer's name and deallocates the memory
  • B: Prints the customer's name and keeps the memory allocated
  • C: Deletes the queue and deallocates all pointers
  • D: Allocates new memory for the customer
View Answer
A

Q322: Why are pointers created inside the loadCustomer function still valid after the function returns?
  • A: Because they are stored in the queue which is still valid
  • B: Because they are global pointers
  • C: Because the objects they point to are on the stack
  • D: Because the pointers themselves are not destroyed
View Answer
A

Q323: How does dynamic memory allocation help when dealing with large objects or arrays?
  • A: By creating objects on the stack
  • B: By creating objects on the heap
  • C: By creating temporary objects
  • D: By creating references to large objects
View Answer
B

Q324: What is a dangling pointer?
  • A: A pointer that points to an invalid memory location
  • B: A pointer that points to a valid object
  • C: A pointer that is not initialized
  • D: A pointer that points to a new object
View Answer
A

Q325: What is the primary difference between stack memory and heap memory in terms of growth direction?
  • A: Stack grows upward, heap grows downward
  • B: Stack and heap both grow upward
  • C: Stack grows downward, heap grows upward
  • D: Stack grows upward, heap grows downward
View Answer
C

Q326: What is the impact of an endless recursive call on the stack memory?
  • A: It causes stack overflow
  • B: It increases heap size
  • C: It reduces heap size
  • D: It causes heap overflow
View Answer
A

Q327: Why are references often used as function parameters with const keyword?
  • A: To ensure the parameter is not modified and avoid copying
  • B: To allow the function to modify the parameter
  • C: To pass the parameter by value
  • D: To create a new instance of the parameter
View Answer
A

Q328: What does the const keyword in C++ do when used with a reference parameter?
  • A: Prevents the function from modifying the parameter
  • B: Allows the function to modify the parameter
  • C: Forces the function to create a copy of the parameter
  • D: Enables modification of the reference object
View Answer
A

Q329: When is it appropriate to use a const keyword at the end of a member function signature?
  • A: To allow the function to modify member variables
  • B: To ensure the function does not modify member variables
  • C: To prevent the function from being called
  • D: To make the function private
View Answer
B

Q330: What is the key feature of an AVL tree compared to a regular binary search tree?
  • A: It allows any height difference between left and right subtrees
  • B: It keeps the height difference between left and right subtrees within 1
  • C: It maintains a complete binary tree structure
  • D: It uses only one child for each node
View Answer
B

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now