C++ MCQ ( 91-120)

91. Which of the following operators is used to dereference a pointer in C++?
a) &
b) *
c) ->
d) %

Answer: b) *


92. What does the ‘this’ pointer in C++ refer to?
a) A pointer to the class itself.
b) A pointer to the current function.
c) A pointer to the calling object.
d) A pointer to the main function.

Answer: c) A pointer to the calling object.


93. Which of the following is true about the ‘mutable’ keyword in C++?
a) It allows a member variable to be modified even if the object is const.
b) It allows the function to be overridden in the derived class.
c) It prevents modification of the variable.
d) It applies to static member variables.

Answer: a) It allows a member variable to be modified even if the object is const.


94. Which of the following types of inheritance is not allowed in C++?
a) Single inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Circular inheritance

Answer: d) Circular inheritance


95. What does the ‘explicit’ keyword do when applied to a constructor in C++?
a) It prevents implicit type conversions.
b) It allows implicit type conversions.
c) It defines a function as virtual.
d) It allows automatic memory management.

Answer: a) It prevents implicit type conversions.


96. What will be the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int a = 3, b = 5;  
    cout << ++a + b-- << endl;  
    return 0;  
}  

a) 8
b) 9
c) 7
d) 10

Answer: a) 8


97. Which of the following is used to handle exceptions in C++?
a) throw
b) catch
c) try
d) All of the above

Answer: d) All of the above


98. What is the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int arr[] = {10, 20, 30};  
    cout << arr[1] << endl;  
    return 0;  
}  

a) 10
b) 20
c) 30
d) 0

Answer: b) 20


99. Which of the following is true about the ‘new[]’ operator in C++?
a) It is used to allocate memory for arrays.
b) It is used to allocate memory for individual objects.
c) It cannot be used to allocate memory dynamically.
d) It is only for class objects.

Answer: a) It is used to allocate memory for arrays.


100. What is the difference between a reference and a pointer in C++?
a) A reference cannot be reassigned to another object.
b) A reference can hold null values.
c) A pointer is safer than a reference.
d) A reference does not need dereferencing.

Answer: a) A reference cannot be reassigned to another object.


101. Which of the following is the correct syntax for declaring a constant pointer in C++?
a) int* const ptr;
b) const int ptr*;
c) const ptr int*;
d) int const ptr*;

Answer: a) int* const ptr;


102. Which of the following C++ features is implemented using the concept of polymorphism?
a) Function overloading
b) Operator overloading
c) Inheritance
d) All of the above

Answer: d) All of the above


103. What is the purpose of the ‘sizeof’ operator in C++?
a) It returns the size of a variable in bytes.
b) It checks if the variable is null.
c) It dynamically allocates memory.
d) It initializes the size of an array.

Answer: a) It returns the size of a variable in bytes.


104. What is the correct way to define a class in C++?
a) class MyClass { };
b) MyClass class { };
c) class MyClass[ ];
d) MyClass = class { };

Answer: a) class MyClass { };


105. Which of the following is true about dynamic memory allocation in C++?
a) The ‘new’ operator allocates memory at runtime.
b) Memory allocated using ‘new’ must be freed using ‘malloc’.
c) Memory allocated using ‘delete’ can be freed using ‘new’.
d) The ‘new’ operator allocates memory on the stack.

Answer: a) The ‘new’ operator allocates memory at runtime.


106. Which of the following is true about destructors in C++?
a) Destructors have a return type.
b) Destructors are called explicitly by the user.
c) A class can have multiple destructors.
d) Destructors are automatically called when an object goes out of scope.

Answer: d) Destructors are automatically called when an object goes out of scope.


107. Which of the following statements about arrays in C++ is correct?
a) Arrays are of fixed size and cannot be resized.
b) Arrays are dynamic in size.
c) Arrays can only store data of type ‘int’.
d) Arrays can store data of multiple types.

Answer: a) Arrays are of fixed size and cannot be resized.


108. Which of the following is used for defining a macro in C++?
a) #macro
b) #function
c) #define
d) #define_macro

Answer: c) #define


109. What will be the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int a = 5;  
    cout << a++ + ++a << endl;  
    return 0;  
}  

a) 10
b) 11
c) 12
d) 9

Answer: b) 11


110. Which of the following functions can be used to read a single character from the user in C++?
a) scanf()
b) getch()
c) getchar()
d) cin >>

Answer: c) getchar()


111. What is the purpose of the ‘friend’ function in C++?
a) It allows non-member functions to access private and protected members of a class.
b) It allows a class to be declared as a friend of another class.
c) It prevents a function from being called outside the class.
d) It automatically declares all functions as friends.

Answer: a) It allows non-member functions to access private and protected members of a class.


112. What will be the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int a = 2, b = 3;  
    cout << a * b << endl;  
    return 0;  
}  

a) 5
b) 6
c) 8
d) 7

Answer: b) 6


113. Which of the following data types can be used as a template argument in C++?
a) Basic data types
b) Class types
c) Pointers
d) All of the above

Answer: d) All of the above


114. Which of the following will declare an integer pointer in C++?
a) int* ptr;
b) int ptr;
c) ptr int
;
d) int ptr*;

Answer: a) int* ptr;


115. What will be the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int arr[3] = {5, 10, 15};  
    cout << arr[0] + arr[2] << endl;  
    return 0;  
}  

a) 15
b) 25
c) 20
d) 30

Answer: b) 25


116. Which of the following is true about function overloading in C++?
a) Overloading is based on the return type.
b) Function overloading is resolved at compile-time.
c) Functions with the same name but the same parameters can be overloaded.
d) Function overloading is not allowed in C++.

Answer: b) Function overloading is resolved at compile-time.


117. What is the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int a = 3, b = 4;  
    cout << a == 3 && b == 4 << endl;  
    return 0;  
}  

a) 1
b) 0
c) true
d) false

Answer: a) 1


118. What is the correct way to define a constructor in C++?
a) void MyClass() {}
b) MyClass() {}
c) MyClass() : {}
d) void MyClass() : {}

Answer: b) MyClass() {}


119. What will be the output of the following code?

#include<iostream>  
using namespace std;  
int main() {  
    int x = 10;  
    cout << ++x << endl;  
    return 0;  
}  

a) 10
b) 11
c) 1
d) x

Answer: b) 11


120. Which of the following C++ features allows an object to be passed by reference to a function?
a) Function overloading
b) Pass-by-reference
c) Function pointers
d) Constructor overloading

Answer: b) Pass-by-reference

Leave a Reply