CPP Imp MCQ PS
CPP Imp MCQ PS
Practice Sheet
3. Which of the following best describes the role of namespaces
Basic Data Structures using C++ (24CSH-103)
in C++?
MCQ-format breakdown
a) Allocating dynamic memory
b) Grouping similar variables
General Instructions :
c) Preventing name conflicts in large programs
1. The exam will be conducted in 2 sections
d) Limiting access to private data
2. Section A will contain 40 MCQ’s of 1 mark each.
3. Section B will contain 8 passage based questions with 5
4. What is the correct use of cin and cout in C++?
questions respectively, each of which would carry 3 marks
a) cin >> for output, cout << for input
each.
b) cin << for output, cout >> for input
4. Time of the examination will be 2 hours. After that the test
c) cin >> for input, cout << for output
will not accept any further answers.
d) cin << for input, cout >> for output
Total marks : 160
5. What happens if a member function is defined outside the class
without using the scope resolution operator?
Section A a) It results in compilation error
b) It will be treated as a global function
1. Which of the following is not a feature of Object-Oriented c) It will be an inline function by default
Programming in C++? d) It becomes private automatically
a) Data Hiding
b) Message Passing 6. Which access specifier allows class members to be
c) Procedural Functions inaccessible outside the class but accessible to derived classes?
d) Polymorphism a) public
b) private
2. In which scenario would a procedure-oriented approach be c) protected
more suitable than object-oriented? d) friend
a) When real-world modeling is required
b) When modular reusability is the goal 7. Choose the correct statement about constructors in C++:
c) When the focus is on sequential task execution a) Constructors can have return types
b) Constructors must always be virtual
c) Constructors are invoked automatically when an object is created class A { public: void display(); };
d) Constructors can be called manually after object creation class B : public A {};
class C : public B {};
8. Which statement about destructors is true?
a) Destructors can be overloaded
b) Destructors take arguments What kind of inheritance is this?
c) Destructors have the same name as the class with a ~ prefix a) Multiple inheritance
d) Destructors are called only if explicitly invoked b) Hybrid inheritance
c) Multilevel inheritance
9. Which mode of inheritance makes public members of the base d) Hierarchical inheritance
class become private in the derived class?
13. Which of the following best differentiates data from
a) Private inheritance
information?
b) Protected inheritance
a) Data is always accurate; information is not
c) Public inheritance
b) Data is processed information
d) Virtual inheritance
c) Information is raw, data is processed
d) Data is raw facts; information is processed data
10. Which of the following represents a correct example of multiple
inheritance? 14. Which of the following is a non-linear data structure?
a) class B : public A {} a) Queue
b) class B : public A, public C {} b) Stack
c) class B : private A {} c) Array
d) class B { A obj; }; d) Graph
11. Which type of inheritance may lead to ambiguity due to 15. Which operation is not common across all data structures?
multiple copies of base class members? a) Traversal
a) Multilevel inheritance b) Insertion
b) Hierarchical inheritance c) Sorting
c) Multiple inheritance d) Deletion
d) Hybrid inheritance
16. If an algorithm has a time complexity of O(n²), what does it
12. Consider the following: mean?
a) Time grows linearly with input
b) Time doubles with every input a) 7
c) Time grows exponentially with input b) 12
d) Time grows quadratically with input size c) 10
d) 6
17. What is the correct index range for a linear array arr[6] in
C/C++? 22. What will happen if you try to access an array element beyond
a) 1 to 6 its defined size in C++?
b) 0 to 5 a) Compilation error
c) 1 to 5 b) Runtime error
d) 0 to 6 c) Undefined behavior
d) The element will be auto-initialized to zero
18. Which of the following best describes the worst-case time
complexity of linear search on an array of size n? 23. What does a pointer actually store?
a) O(log n) a) The name of the variable
b) O(n) b) The data value of the variable
c) O(n log n) c) The address of a variable
d) O(1) d) The size of the variable
19. What is the key condition for applying binary search? 24. Which of the following is a major advantage of linked lists
a) Array must be unsorted over arrays?
b) Array must be sorted a) Direct access to elements
c) Array must have only unique elements b) Less memory usage
d) Array must have all elements positive c) Dynamic memory allocation
d) Fixed size allocation
20. Which of the following sorting algorithms always compares
adjacent elements? 25. In a singly linked list, each node contains:
a) Insertion Sort a) Only data
b) Bubble Sort b) Data and two pointers
c) Selection Sort c) Data and one pointer
d) Quick Sort d) Only a pointer
21. In a 2D array declared as int arr[3][4], how many total elements 26. What will be the output of traversing an empty linked list?
can be stored? a) Compilation error
b) Garbage values c) The top element
c) Null pointer exception d) Any element randomly
d) No output
32. What does a stack underflow condition signify?
27. Inserting a node at the beginning of a singly linked list involves: a) Stack is full
a) Shifting all elements b) No memory is available
b) Reversing the list c) No element to pop
c) Modifying the head pointer d) Stack is not initialized
d) Traversing the entire list
33. In a linked list implementation of a stack, where is the top of
28. The time complexity of insertion at the end of a singly linked the stack stored?
list without a tail pointer is: a) At the end of the list
a) O(1) b) In the middle
b) O(log n) c) As the head of the list
c) O(n) d) At a fixed index
d) O(n log n)
34. Which of the following is true about postfix expression
29. Which of the following is not true for linked list? evaluation using a stack?
a) Elements are stored in contiguous memory a) Operators are pushed, operands popped
b) Insertion and deletion are faster than arrays b) Operands are pushed, then popped with operator
c) Dynamic memory allocation is used c) Expression is stored and reversed
d) Each node has at least one pointer d) Parentheses are mandatory
30. What happens to memory when a node is deleted from a linked 35. What is the postfix form of: A + B * C?
list but its pointer is not set to NULL? a) ABC*+
a) Memory is automatically reclaimed b) AB+C*
b) The node is still accessible c) A+BC*
c) Memory leak may occur d) A*BC+
d) Program will crash immediately
36. While converting infix to postfix, which data structure is best
31. In a stack, which element is accessible at any given time? used for storing operators?
a) The element at the bottom a) Queue
b) The element with maximum value b) Array
c) Stack Section B
d) Linked List
Passage 1: Understanding OOP through a Real-Life
37. In a linear queue implemented using arrays, which condition
signifies overflow? Analogy
a) front == rear
Imagine you're developing a software to manage an online library.
b) rear == MAX - 1
You decide to use Object-Oriented Programming to make your
c) front == MAX - 1
system modular and reusable. You create classes like Book,
d) rear == 0
Member, and Librarian. Each class has specific attributes (like title,
38. In a circular queue, what happens when rear is at the last author, memberID) and behaviors (like issueBook(), returnBook(),
position and an insertion is needed at the beginning? etc.). You also use concepts like encapsulation to hide internal data,
a) Insertion fails and inheritance where Librarian inherits properties from Member
b) Array is expanded but has additional privileges.
c) Rear wraps to index 0
Q41. Which OOP concept ensures that title and author in class
d) Rear is set to front
Book are not directly accessible from outside the class?
39. Which queue allows insertion at one end and deletion at the
a) Abstraction
other?
b) Inheritance
a) Deque
c) Polymorphism
b) Circular Queue
d) Encapsulation
c) Linear Queue
d) Priority Queue Q42. If Librarian is a derived class of Member, and it adds new
functions like addBook(), this demonstrates:
40. Which of the following is an advantage of circular queue over
linear queue? a) Function overloading
a) Better sorting of data b) Inheritance with extension
b) Avoids memory fragmentation c) Encapsulation
c) More efficient use of memory d) Static binding
d) Fixed-size memory usage is avoided
Q43. Which feature of OOP does creating classes like Book,
Member, and Librarian best represent?
a) Polymorphism
b) Modularity class Dog : public Animal {
c) Dynamic binding public:
d) Friend function void bark() {
cout << "Dog barks" << endl;
Q44. Which of the following is not a feature of Object-Oriented }
Programming? };
a) Code compactness
Q46. What type of inheritance is used in this program?
b) Syntax simplification
c) Flexibility and maintainability a) Multiple
d) Performance optimization b) Hierarchical
c) Single
Passage 2: Code Snippet on Classes and Inheritance d) Hybrid
#include <iostream> Q47. The function speak() is accessible from object d because:
using namespace std;
a) It's defined inside Dog
b) It’s declared as virtual
class Animal {
c) Dog privately inherits Animal
public:
d) Dog publicly inherits Animal
void speak() {
cout << "Animal speaks" << endl;
Q48. What is the output of the above program?
}
};
a) Animal speaks They then experiment with sorting techniques like Bubble Sort and
b) Dog barks Selection Sort to understand performance differences.
c) Animal speaks
Dog barks Q51. What is a key requirement for applying Binary Search on an
d) Compile-time error array?
Q49. If bark() were defined as inline void bark() {...}, what would be a) All elements must be unique
the implication? b) Array should be sorted
c) Array must be of fixed size
a) It will no longer be a class member d) Elements must be strings
b) It will be compiled as a macro
c) Its body is substituted at the call site Q52. If an array of 10,000 unsorted numbers is sorted using
d) It cannot access other class members Bubble Sort, what is the time complexity?
a) Bubble Sort
b) Selection Sort
Passage 3: The Rise of Structured Storage c) Insertion Sort
d) Quick Sort
A company is developing a contact tracing system that needs to
store, insert, and retrieve phone numbers of people. Initially, they Q54. Inserting an element in the middle of a linear array of size n
use a linear array to store this information. However, as the size of takes:
data grows, operations like insertion in the middle and searching
a) O(1) time
become time-consuming. To optimize search time, they implement
b) O(log n) time
Binary Search, but soon realize that the array needs to be sorted.
c) O(n) time
d) Constant space but logarithmic time
Q55. Which searching algorithm is best suited for unsorted a) Static array
arrays? b) 1D array only
c) Linked list
a) Linear Search d) Array of pointers
b) Binary Search
c) Fibonacci Search Q58. What is the correct way to access the element at row 2,
d) Interpolation Search column 3 in grid using pointer notation?
Q57. Which data structure is most suitable to represent such a A ride-booking app uses a singly linked list to maintain a waiting
dynamic 2D game map? queue for drivers. Each node stores driver ID and status. When a
driver accepts a ride, the node is removed from the front of the list.
New drivers coming online are inserted at the end. The linked list Q65. What is the advantage of a linked list over an array in terms
structure helps in dynamic memory allocation and efficient of memory?
insertion/deletion.
a) Less memory access time
Q61. What is the time complexity of inserting a new driver at the b) Fixed size
end of a singly linked list (without tail pointer)? c) Random access
d) Dynamic memory allocation
a) O(1)
b) O(log n) Passage 6: Stack Evaluation in Expression Solving
c) O(n)
d) O(n²) A compiler uses a stack to evaluate postfix expressions like
23*54*+9-. The operands are pushed, and operators pop the last
Q62. Which of the following is true for a singly linked list? two operands to apply the operation. Similarly, during infix to postfix
conversion, operators are pushed based on precedence, and
a) Nodes can only be inserted at the front
parentheses control operator stacking.
b) Each node contains a data field and a pointer to the next node
c) Each node contains a pointer to both previous and next nodes Q66. What is the result of evaluating the postfix expression
d) All nodes are stored in contiguous memory 23*54*+?
Q63. Which pointer should be updated when deleting a node from a) 17
the middle of a singly linked list? b) 26
c) 23
a) Pointer to head
d) 14
b) Pointer to the deleted node
c) Pointer to the node just before the one being deleted Q67. In infix to postfix conversion, which operator is popped first
d) Tail pointer (assuming precedence is equal)?
Q64. What will happen if we try to traverse a linked list without a) Rightmost
checking for NULL pointers? b) Leftmost
c) Top of stack
a) Faster traversal
d) Bottom of stack
b) Segmentation fault
c) Skips the last node Q68. Which of the following is not a valid postfix expression?
d) Compiles but never runs
a) 23+ c) Wasted front space
b) 34+5* d) False overflow
c) +23
d) 78*65/- Q72. What is the most suitable solution to the above problem?
Q69. In stack-based expression evaluation, what causes a stack a) Use linked list
underflow? b) Increase array size
c) Use circular queue
a) Pushing too many elements d) Restart the program
b) Popping from an empty stack
c) Expression too long Q73. Which of the following operations decreases the value of
d) Using infix instead of postfix front?
a) 2 b) 3 c) 4 d) 5
Passage 7: Queue Management in Hospitals
Q75. What condition indicates that a circular queue is full (size =
A hospital maintains a linear queue of patients. Patients are added
n)?
at the rear and served from the front. The system uses an array to
implement this, but faces an issue: after several patients are a) rear == front
removed, no new patients can be added even though space is b) (rear + 1) % n == front
available at the front. c) rear == n
d) front == -1
Q71. What is this queue implementation problem known as?
a) Queue overflow
b) Stack underflow
Passage 8: Linked Representation of Stack and Queue a) Has only one element
b) Is full
In a classroom simulation, each student joining the class is added c) Is empty
to a queue implemented using linked representation. Meanwhile, a d) Is circular
stack stores each student's most recent question. The stack uses
dynamic memory, growing as needed and freeing memory after Q80. In linked implementation of stack, how do you push an
each answer. element?
Q76. What is the advantage of linked representation over array for a) Insert at tail
queues? b) Insert at front
c) Traverse then insert
a) More memory usage d) Use middle node
b) Fixed size
c) No overflow if memory is available
d) Slower insertion
a) Bottom
b) Top
c) Rear
d) Head
a) Queue
b) Stack
c) Linked List
d) Array