Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
Q311: What does the const keyword indicate when used in a function parameter?
- A: The parameter cannot be modified inside the function
- B: The parameter must be initialized before use
- C: The parameter must be passed by pointer
- D: The parameter can be modified
View Answer
A
Q312: In the function void loadCustomer(Queue & q), what does Queue & q signify?
- A: Passing by value
- B: Passing by pointer
- C: Passing by reference
- D: Passing by address
View Answer
C
Q313: What happens to local variables created in a function once the function exits?
- A: They are saved for future use
- B: They are moved to heap memory
- C: They are destroyed
- D: They are passed to another function
View Answer
C
Q314: When using dynamic memory allocation, which operator is used to allocate memory?
- A: malloc
- B: free
- C: new
- D: delete
View Answer
C
Q315: What is a common problem associated with using references to transient objects?
- A: Memory leaks
- B: Dangling pointers
- C: Memory overflow
- D: Stack overflow
View Answer
B
Q316: In the provided code, what does Customer * c1 = new Customer(“irfan”); do?
- A: Creates a new Customer object on the stack
- B: Creates a new Customer object on the heap
- C: Creates a pointer to a Customer object on the stack
- D: Creates a reference to a Customer object
View Answer
B
Q317: Why is delete used in the function serviceCustomer?
- A: To remove a pointer from the queue
- B: To free up the memory allocated for a Customer object
- C: To delete a reference variable
- D: To remove an element from the stack
View Answer
B
Q318: What will happen if a pointer is accessed after the object it points to has been deleted?
- A: It will cause a segmentation fault
- B: The pointer will be reallocated
- C: The program will execute normally
- D: The pointer will automatically be set to null
View Answer
A
Q319: What is the role of the activation record in the call stack?
- A: To store the function's local variables and parameters
- B: To allocate memory for dynamic variables
- C: To manage the heap memory allocation
- D: To keep track of global variables
View Answer
A
Q320: What is the purpose of passing an object by reference in the enqueue method of the queue?
- A: To avoid copying the object and directly modify the original
- B: To create a copy of the object for safety
- C: To use the object temporarily in the method
- D: To allocate new memory for the object
View Answer
A