Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 17
Q301:
How does the function intMinus3 affect the argument passed to it?
A. It decreases the value of the argument and returns the new value
B. It increases the value of the argument and returns the new value
C. It decreases the value of the argument but does not return it
D. It keeps the value unchanged
Correct Answer:
A
Chapter: 17
Q302:
In which scenario is a reference variable preferred over a pointer?
A. When you want to modify the original object without copying
B. When you want to create a new object
C. When you want to avoid modifying the original object
D. When you need a dynamic memory allocation
Correct Answer:
A
Chapter: 17
Q303:
What is the call stack used for during function calls?
A. To store function parameters, local variables, and return addresses
B. To allocate memory for global variables
C. To store function definitions and declarations
D. To keep track of pointers and their values
Correct Answer:
A
Chapter: 17
Q304:
What is the result of calling intMinus1(31) in the function caller?
A. 30, and myInt remains 31
B. 30, and myInt changes to 30
C. 31, and myInt remains 31
D. 31, and myInt changes to 30
Correct Answer:
A
Chapter: 17
Q305:
What does passing an address to a function allow you to do?
A. Modify the original variable value
B. Create a copy of the variable
C. Pass a new variable
D. Increase the memory usage
Correct Answer:
A
Chapter: 17
Q306:
What does the code intMinus2(&myInt); do in the function caller?
A. It decreases the value of myInt by 2
B. It increases the value of myInt by 2
C. It decreases the value of myInt by 1
D. It increases the value of myInt by 1
Correct Answer:
A
Chapter: 17
Q307:
Why is intMinus3 using a reference variable instead of a pointer?
A. To avoid explicit dereferencing and still modify the original variable
B. To avoid modifying the original variable
C. To copy the variable value
D. To allocate new memory
Correct Answer:
A
Chapter: 17
Q308:
What will be the output of cout << myInt << retVal; after calling intMinus2(&myInt); if myInt is initially 31?
A. 31 29
B. 29 31
C. 31 31
D. 29 29
Correct Answer:
A
Chapter: 18
Q309:
What is the main purpose of using reference variables in C++?
A. To create copies of variables
B. To pass variables by value
C. To avoid copying variables and modify original values
D. To store values temporarily
Correct Answer:
C
Chapter: 18
Q310:
Which operator is used to pass parameters by reference in C++?
A. &
B. *
C. ->
D. []
Correct Answer:
A
Chapter: 18
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
Correct Answer:
A
Chapter: 18
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
Correct Answer:
C
Chapter: 18
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
Correct Answer:
C
Chapter: 18
Q314:
When using dynamic memory allocation, which operator is used to allocate memory?
A. malloc
B. free
C. new
D. delete
Correct Answer:
C
Chapter: 18
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
Correct Answer:
B
Chapter: 18
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
Correct Answer:
B
Chapter: 18
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
Correct Answer:
B
Chapter: 18
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
Correct Answer:
A
Chapter: 18
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
Correct Answer:
A
Chapter: 18
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
Correct Answer:
A