Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
Q151: What does the 'pop' function return in the Stack class template?
- A: The current size of the stack
- B: The element on the top of the stack
- C: The last element added
- D: A reference to the first element
View Answer
B
Q152: What is the role of the 'empty()' function in the Stack class template?
- A: Adds an element
- B: Removes an element
- C: Checks if the stack is empty
- D: Sorts the elements in the stack
View Answer
C
Q153: In the Stack class template, what is 'MAXSTACKSIZE'?
- A: The current number of elements
- B: The maximum number of elements allowed
- C: The minimum number of elements required
- D: The size of one element in memory
View Answer
B
Q154: What is the function of the 'nodes' pointer in the Stack class template?
- A: Points to the first element in the stack
- B: Points to the last element in the stack
- C: Points to the array of elements
- D: Points to the function in the stack
View Answer
C
Q155: In the function call stack, what is the first entry pushed onto the stack?
- A: The first argument
- B: The return address
- C: The last argument
- D: The function name
View Answer
B
Q156: Which C++ feature allows for the creation of generic classes and functions?
- A: Pointers
- B: References
- C: Templates
- D: Namespaces
View Answer
C
Q157: What type of data does the Stack class template handle when instantiated as 'Stack<int>'?
- A: Characters
- B: Integers
- C: Floats
- D: Strings
View Answer
B
Q158: What is the return type of the 'pop' function in the Stack class template?
- A: int
- B: void
- C: T (generic data type)
- D: char
View Answer
C
Q159: Which method in the Stack class template checks if the stack is empty?
- A: pop
- B: push
- C: empty
- D: peek
View Answer
C
Q160: What is the function of the 'peek' method in the Stack class template?
- A: Returns and removes the top element
- B: Returns the top element without removing it
- C: Adds an element to the top of the stack
- D: Clears the stack
View Answer
B