Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
C
Q310: Which operator is used to pass parameters by reference in C++?
- A: &
- B: *
- C: ->
- D: []
View Answer
A