You are on page 1of 19

1. What is the primary purpose of the cout function in C++?

•A. Reading input data


•B. Displaying output data
•C. Allocating memory
•D. Declaring variables
(Answer: B)
2. Which C++ function is used to accept user input?

•A. print()
•B. cin
•C. output()
•D. scanf()
(Answer: B)
3. In C++, what is the keyword used to define a class?

•A. struct
•B. class
•C. type
•D. object
(Answer: B)
4. Which library should be included to use the sqrt() function in C++?

•A. cmath
•B. math.h
•C. iostream
•D. iomanip
(Answer: A)
5. What is the purpose of variables in C++?

•A. To perform mathematical operations


•B. To store and manipulate data
•C. To define constants
•D. To control the flow of a program
(Answer: B)
6. Which data structure stores elements in a sequential order and allows
direct access to any element using an index?

•A. Linked list


•B. Stack
•C. Array
•D. Queue
(Answer: C)
7. In C++, what is a linked list?

•A. A type of array


•B. A linear data structure
•C. A type of variable
•D. A sorting algorithm
(Answer: B)
8. Which of the following is an example of an iterative control structure in
C++?

•A. for loop


•B. switch statement
•C. if-else statement
•D. do-while loop
(Answer: A)
9. What is the primary purpose of the Big-O notation in computer science?

•A. Describing the size of input data


•B. Analyzing the efficiency of algorithms
•C. Representing variable types
•D. Specifying data types in C++
(Answer: B)
10.What does Big-Theta notation describe in the context of algorithm
analysis?

•A. Worst-case time complexity


•B. Average-case time complexity
•C. Best-case time complexity
•D. Tight bound on the growth rate of an algorithm
(Answer: D)

Which C++ keyword is used to dynamically allocate memory for a variable in the
heap?

•A. stack
•B. alloc
•C. malloc
•D. new
(Answer: D)
12.In C++, what is the purpose of the break statement in a loop?

•A. To exit the loop prematurely


•B. To skip the current iteration and move to the next one
•C. To restart the loop from the beginning
•D. To check the loop condition
(Answer: A)
13.Which type of inheritance allows a class to inherit properties from
multiple base classes in C++?

•A. Single inheritance


•B. Multiple inheritance
•C. Hierarchical inheritance
•D. Multilevel inheritance
(Answer: B)
14.What does the sizeof operator in C++ return?

•A. Size of a variable in bytes


•B. Address of a variable
•C. Value of a variable
•D. Type of a variable
(Answer: A)
15.What is the purpose of the const keyword in C++?

•A. To declare a constant variable


•B. To define a class
•C. To allocate memory
•D. To perform mathematical operations
(Answer: A)
16.Which of the following is a sorting algorithm with a time complexity of
O(n^2) in the worst case?

•A. Quick Sort


•B. Merge Sort
•C. Bubble Sort
•D. Radix Sort
(Answer: C)
17.What is the primary goal of the Bubble Sort algorithm?

•A. Minimizing memory usage


•B. Sorting elements in ascending order
•C. Achieving optimal time complexity
•D. Randomizing the order of elements
(Answer: B)

18.In C++, what is the purpose of the ++ operator when applied to a


variable?

•A. Increment the variable by 1


•B. Decrement the variable by 1
•C. Double the variable
•D. Assign the variable a new value
(Answer: A)
19.What is the primary purpose of recursion in programming?

•A. Improving memory efficiency


•B. Simplifying code structure
•C. Dividing a problem into smaller subproblems
•D. Executing the same block of code repeatedly
(Answer: C)
20.Which notation among Big-O, Big-Theta, and Big-Omega represents
the tightest upper bound for the growth rate of an algorithm?

•A. Big-O
•B. Big-Theta
•C. Big-Omega
•D. All represent the same bound
(Answer: A)

What is the purpose of the virtual keyword in C++ in the context of object-
oriented programming?

•A. To create a constant variable


•B. To declare a base class
•C. To indicate that a function can be overridden
•D. To perform bitwise operations
(Answer: C)
22.Which container in C++ is used to implement a Last In, First Out
(LIFO) data structure?

•A. Queue
•B. Set
•C. Stack
•D. List
(Answer: C)
23.What is the role of the std::cin.ignore() function in C++?

•A. Ignores compiler warnings


•B. Ignores user input
•C. Ignores characters in the input buffer
•D. Ignores syntax errors
(Answer: C)
24.Which of the following statements regarding the complexity of the
binary search algorithm is correct?

•A. O(n)
•B. O(log n)
•C. O(n^2)
•D. O(1)
(Answer: B)
25.In C++, what is the purpose of the nullptr keyword?

•A. Representing a null value for pointers


•B. Creating a new variable
•C. Defining a constant value
•D. Allocating memory for an array
(Answer: A)
26.What is the primary advantage of using the insertion sort algorithm
over other sorting algorithms for small datasets?

•A. Low time complexity


•B. Simplicity of implementation
•C. Stability in sorting
•D. Parallel processing capabilities
(Answer: B)
27.Which of the following is an example of a data type in C++?

•A. void
•B. loop
•C. execute
•D. output
(Answer: A)
28.What does the const qualifier mean when applied to a member
function in a C++ class?

•A. The function cannot be called


•B. The function is not allowed to modify the object's data
members
•C. The function can only be called by other member functions
•D. The function is constant and cannot change
(Answer: B)
29.Which of the following is a disadvantage of using recursion in
programming?

•A. Improved code readability


•B. Increased memory usage
•C. Faster execution speed
•D. Simplicity in debugging
(Answer: B)
30.What is the primary purpose of the typeid operator in C++?

•A. Allocating memory


•B. Checking the type of an expression
•C. Performing mathematical operations
•D. Defining data structures
(Answer: B)

Which C++ keyword is used to indicate the beginning of a function definition?

•A. begin
•B. start
•C. function
•D. void
(Answer: D)
32.What is the purpose of the getline() function in C++?

•A. Reading a single character from input


•B. Reading a line of text from input
•C. Writing a line of text to output
•D. Creating a new line in the console
(Answer: B)
33.In C++, what does the this pointer refer to in a member function?

•A. The previous object


•B. The next object
•C. The current object
•D. The base object
(Answer: C)
34.Which library in C++ provides functions for dynamic memory
allocation and deallocation?

•A. cmath
•B. cstdlib
•C. cstring
•D. cstdio
(Answer: B)
35.What is the primary purpose of the do-while loop in C++?

•A. Executing a block of code only if a condition is true


•B. Iterating over a range of values
•C. Repeating a block of code until a condition is false
•D. Skipping the current iteration and moving to the next one
(Answer: C)
36.Which of the following is a correct way to declare a pointer variable in
C++?

•A. int* pointerVar;


•B. pointerVar = int;
•C. pointerVar int*;
•D. pointerVar = ∫
(Answer: A)
37.What is the primary purpose of the std::setw() function in C++?

•A. Setting the width of the console window


•B. Setting the width of the output field
•C. Setting the width of an array
•D. Setting the width of a variable
(Answer: B)
38.Which of the following best describes the purpose of the const_cast
operator in C++?

•A. Casting away the const qualifier from a pointer or reference


•B. Adding a const qualifier to a variable
•C. Casting a variable to a constant value
•D. Casting a constant variable to a non-constant value
(Answer: A)
39.What is the significance of the delete keyword in C++ when working
with dynamic memory allocation?

•A. Deleting a file from the system


•B. Freeing allocated memory
•C. Deleting a variable from the program
•D. Deleting a class definition
(Answer: B)
40.Which of the following sorting algorithms has a time complexity of O(n
log n) in the average and worst case?

•A. Bubble Sort


•B. Merge Sort
•C. Selection Sort
•D. Insertion Sort
(Answer: B)

What is the purpose of the friend keyword in C++ when used in the context of
classes?

•A. Indicating a friendly class


•B. Allowing access to private members of another class
•C. Defining a new class
•D. Specifying a class as a friend of the compiler
(Answer: B)
42.Which C++ keyword is used to explicitly indicate that a function won't
modify the object it is called on?

•A. immutable
•B. unchangeable
•C. const
•D. readonly
(Answer: C)
43.In C++, what is the purpose of the typeid operator when used with
type_info objects?

•A. Comparing two objects


•B. Retrieving type information of an object
•C. Converting between data types
•D. Checking if an object is null
(Answer: B)
44.What is the primary function of the std::set container in C++?

•A. Storing elements in a specific order


•B. Storing unique elements in sorted order
•C. Storing elements in a stack
•D. Storing elements in a queue
(Answer: B)
45.Which keyword is used to implement exception handling in C++?

•A. catch
•B. finally
•C. throw
•D. try
(Answer: C)
46.What is the role of the const_iterator in C++ when used with
containers?

•A. Modifying container elements


•B. Iterating over container elements
•C. Creating a constant container
•D. Declaring a container
(Answer: C)
47.In C++, what does the explicit keyword indicate in the context of a
constructor?

•A. The constructor can only be called implicitly


•B. The constructor can be called with any type
•C. The constructor can be called explicitly or implicitly
•D. The constructor cannot be called
(Answer: A)
48.Which of the following correctly represents the syntax for declaring a
pure virtual function in C++?

•A. virtual void myFunction() = 0;


•B. pure virtual void myFunction();
•C. virtual void myFunction() : 0;
•D. abstract void myFunction();
(Answer: A)
49.What is the purpose of the std::map container in C++?

•A. Storing elements in a random order


•B. Storing elements in a sorted order
•C. Storing unique elements in a stack
•D. Storing elements in a linked list
(Answer: B)
50.In C++, what is the role of the const_cast operator?

•A. Casting away the const qualifier from a variable


•B. Adding a const qualifier to a variable
•C. Creating a constant variable
•D. Casting a constant variable to another constant value
(Answer: A)

What does the std::move function facilitate in C++?

•A. Moving the cursor in console output


•B. Transferring ownership of resources from one object to
another
•C. Moving elements to the front of a container
•D. Moving the program execution to a different function
(Answer: B)
52.Which of the following is a correct way to define a macro in C++ using
the #define directive?

•A. #define MACRO_NAME = 10


•B. #define MACRO_NAME (10)
•C. #define MACRO_NAME 10
•D. #define MACRO_NAME = (10)
(Answer: C)
53.What is the purpose of the std::forward function in C++?

•A. Forwarding function calls to another function


•B. Forwarding template arguments to another function
•C. Forwarding function declarations
•D. Forwarding references to the past
(Answer: B)
54.In C++, what does the const qualifier indicate when used with a
member function?

•A. The function cannot be called


•B. The function can only be called by other const member
functions
•C. The function is not allowed to modify the object's data
members
•D. The function can only be called on constant objects
(Answer: C)
55.Which of the following best describes the purpose of the volatile
keyword in C++?

•A. Indicating a variable that can change asynchronously


•B. Forcing a variable to remain constant
•C. Signifying a constant pointer
•D. Specifying a variable that cannot be modified
(Answer: A)
56.What is the primary purpose of the std::bitset class in C++?

•A. Representing a fixed-size sequence of bits


•B. Sorting elements in a container
•C. Defining a set of constants
•D. Allocating memory for a bit array
(Answer: A)
57.Which of the following is a correct way to open a file for reading in
C++ using the fstream class?

•A. fstream file("filename.txt", ios::read);


•B. fstream file("filename.txt", ios::in);
•C. fstream file("filename.txt", read);
•D. fstream file("filename.txt", input);
(Answer: B)
58.What is the role of the std::mutex class in C++ when dealing with
multithreading?

•A. Allocating memory for a mutex


•B. Locking and unlocking critical sections of code
•C. Defining a constant mutex
•D. Controlling the program execution order
(Answer: B)
59.In C++, what is the primary function of the typeid operator when used
with std::type_info objects?

•A. Identifying the type of an object


•B. Casting a variable to another type
•C. Allocating memory for type information
•D. Performing arithmetic operations on type information
(Answer: A)
60.What is the primary purpose of the noexcept specifier in C++?

•A. Specifying that a function does not throw exceptions


•B. Indicating that a function always throws exceptions
•C. Declaring a function as non-executable
•D. Preventing the use of exception handling in a program
(Answer: A)

In C++, what does the auto keyword indicate when used for variable
declaration?

•A. A variable with automatic storage duration


•B. A variable that can automatically change its type
•C. A variable with automatic type deduction
•D. A variable that can be automatically deleted
(Answer: C)
62.What is the purpose of the std::async function in C++ when working
with concurrency?

•A. Allocating memory asynchronously


•B. Executing a function asynchronously and obtaining a
std::future object
•C. Synchronizing multiple threads
•D. Creating a thread pool
(Answer: B)
63.Which of the following statements accurately describes a lambda
function in C++?

•A. A lambda function is a global function.


•B. A lambda function cannot capture variables.
•C. A lambda function is an anonymous function.
•D. A lambda function can only have one parameter.
(Answer: C)
64.What is the role of the explicit keyword in a C++ constructor with a
single argument?

•A. It allows implicit type conversion.


•B. It prohibits implicit type conversion.
•C. It specifies the type of the argument.
•D. It indicates that the constructor has no arguments.
(Answer: B)
65.What is the primary purpose of the std::accumulate function in C++?

•A. Accumulating values in a container


•B. Adding elements of a container
•C. Initializing a container
•D. Allocating memory for a container
(Answer: B)
66.In C++, what is a template specialization used for?

•A. Creating a generic template


•B. Providing a specific implementation for a specific data type
•C. Specializing the behavior of a class
•D. Allocating memory for a template
(Answer: B)
67.What does the final keyword indicate when applied to a class in C++?

•A. The class cannot have any member functions.


•B. The class cannot be inherited.
•C. The class is the final class in a program.
•D. The class is the first in a series of classes.
(Answer: B)
68.Which C++ feature allows a derived class to inherit the members of
multiple base classes with the same name?

•A. Ambiguity resolution


•B. Multiple inheritance
•C. Hierarchical inheritance
•D. Single inheritance
(Answer: A)
69.What is the purpose of the constexpr specifier in C++?

•A. Specifying a constant expression


•B. Creating a constant variable
•C. Specifying a variable as non-constant
•D. Declaring a constant function
(Answer: A)
70.Which of the following is a correct way to use the std::thread class in
C++ for multithreading?
•A. thread myThread = new thread(myFunction);
•B. thread myThread(myFunction);
•C. myThread.start(myFunction);
•D. startThread(myFunction);
(Answer: B)

What is the purpose of the std::unique_ptr class in C++?

•A. Representing a unique identifier


•B. Managing dynamic memory with automatic deallocation
•C. Defining a unique constant
•D. Creating a unique pointer to a variable
(Answer: B)
72.In C++, what does the explicit keyword indicate when used with a
constructor?

•A. The constructor cannot be called


•B. Implicit type conversion is allowed
•C. Implicit type conversion is prohibited
•D. The constructor has no parameters
(Answer: C)
73.What is the primary purpose of the std::condition_variable class in
C++?

•A. Representing a boolean condition


•B. Controlling access to a shared resource among multiple threads
•C. Specifying a variable as constant
•D. Allocating memory for a condition
(Answer: B)
74.Which of the following is true about the explicit keyword in C++ when
used with a conversion operator?

•A. It allows implicit conversions.


•B. It prohibits implicit conversions.
•C. It only works with user-defined types.
•D. It is used for dynamic casting.
(Answer: B)
75.What is the purpose of the std::move_if_noexcept function in C++?

•A. Moving an object only if it is not noexcept


•B. Moving an object only if it is noexcept
•C. Moving an object regardless of noexcept
•D. Allocating memory for an object
(Answer: A)
76.In C++, what is the purpose of the std::initializer_list class?

•A. Initializing a list of variables


•B. Representing a list of constant values
•C. Initializing a container with a list of values
•D. Allocating memory for a list
(Answer: C)
77.What is the primary use of the std::mutex::try_lock function in C++?

•A. Locking a mutex only if it is available


•B. Locking a mutex unconditionally
•C. Unlocking a mutex
•D. Creating a new mutex
(Answer: A)
78.What does the override keyword indicate in C++ when used with a
member function in a derived class?

•A. Overriding a function from a base class


•B. Creating a new function
•C. Indicating the function as virtual
•D. Specifying a function as const
(Answer: A)
79.Which C++ feature allows a class to inherit members from a base class
as if they were members of the derived class itself?

•A. Friend function


•B. Virtual inheritance
•C. Protected inheritance
•D. Public inheritance
(Answer: B)
80.What is the primary purpose of the std::atomic class in C++ when
working with multithreading?

•A. Creating atomic variables


•B. Allocating memory for a variable
•C. Specifying a variable as constant
•D. Defining a new thread
(Answer: A)
In C++, what is the purpose of the typeid operator when used with
std::type_index objects?

•A. Comparing two types


•B. Storing type information
•C. Retrieving type information of an object
•D. Creating a new type
(Answer: B)
82.What is the primary role of the std::chrono library in C++?

•A. Mathematical operations on complex numbers


•B. Handling date and time operations
•C. Allocating memory for dynamic arrays
•D. Performing bitwise operations
(Answer: B)
83.In C++, what does the explicit keyword indicate when used with a
conversion constructor?

•A. Implicit conversions are allowed


•B. Implicit conversions are prohibited
•C. The constructor has no parameters
•D. The constructor cannot be called
(Answer: B)
84.What is the primary purpose of the std::forward_list container in C++?

•A. Storing elements in a doubly-linked list


•B. Storing elements in a singly-linked list
•C. Storing elements in a stack
•D. Storing elements in a queue
(Answer: B)
85.Which of the following best describes the constexpr specifier in C++?

•A. Specifying that a function cannot be overloaded


•B. Specifying that a function cannot throw exceptions
•C. Specifying that a function can be evaluated at compile time
•D. Specifying that a function is constant and cannot change
(Answer: C)
86.What does the std::back_inserter function do in C++ when working
with containers?

•A. Inserts elements at the front of the container


•B. Inserts elements at the back of the container
•C. Inserts elements at a specified position
•D. Removes elements from the container
(Answer: B)
87.In C++, what is the primary use of the noexcept specifier in a function
declaration?

•A. Specifying that the function cannot be overloaded


•B. Indicating that the function always throws exceptions
•C. Declaring that the function does not throw exceptions
•D. Preventing the use of exception handling in the function
(Answer: C)
88.Which C++ feature allows a derived class to provide a specific
implementation for a function that is already defined in a base class?

•A. Function overloading


•B. Function overriding
•C. Function templating
•D. Function declaration
(Answer: B)
89.What is the purpose of the std::tie function in C++ when working with
tuples?

•A. Creating a new tuple


•B. Unpacking a tuple into individual variables
•C. Sorting the elements of a tuple
•D. Concatenating two tuples
(Answer: B)

90.In C++, what does the std::optional class provide?

•A. An option for dynamic memory allocation


•B. An optional parameter for a function
•C. A way to handle optional values without using null pointers
•D. An optional constructor for a class
(Answer: C)

What is the role of the std::any class in C++?

•A. Representing any data type


•B. Allocating memory for any object
•C. Storing any constant value
•D. Defining any class
(Answer: A)
92.In C++, what does the std::is_same template trait indicate when used
with two type arguments?

•A. Checking if two types are identical


•B. Converting one type to another
•C. Creating a new type
•D. Comparing two type sizes
(Answer: A)
93.What is the purpose of the std::find function in C++ when working with
containers?

•A. Searching for a specified element in a container


•B. Finding the maximum element in a container
•C. Sorting the elements of a container
•D. Initializing a container
(Answer: A)
94.In C++, what does the std::make_shared function facilitate when
working with smart pointers?

•A. Creating a shared pointer from a weak pointer


•B. Allocating memory for a shared pointer
•C. Constructing a shared pointer from a raw pointer
•D. Making a pointer shared among multiple threads
(Answer: C)
95.What is the purpose of the std::filesystem library in C++?

•A. Handling mathematical operations


•B. Manipulating file and directory paths
•C. Creating filesystem objects
•D. Allocating memory for filesystem data
(Answer: B)
96.In C++, what is the primary use of the std::async function when dealing
with asynchronous programming?

•A. Allocating memory asynchronously


•B. Synchronizing multiple threads
•C. Executing a function asynchronously and obtaining a std::future
object
•D. Creating a thread pool
(Answer: C)
97.What is the role of the explicit keyword when used with a conversion
operator in C++?

•A. Allowing implicit conversions


•B. Prohibiting implicit conversions
•C. Specifying the type of the conversion
•D. Enforcing explicit type casting
(Answer: B)
98.Which C++ feature allows a function to accept a variable number of
arguments?

•A. Function overloading


•B. Variadic templates
•C. Function pointers
•D. Function specialization
(Answer: B)
99.What is the purpose of the std::unordered_map container in C++?

•A. Storing elements in a sorted order


•B. Storing unique elements in a stack
•C. Storing elements in a hash table
•D. Storing elements in a linked list
(Answer: C)
100.In C++, what does the std::mutex::lock function do in a multithreading
environment? - A. Unlocks the mutex - B. Attempts to lock the mutex - C.
Initializes the mutex - D. Locks the mutex
(Answer: D)

You might also like