Welcome back to the series on MCQ on C++. In the previous post, we provided you with some multiple-choice questions (MCQs) on C++ that covered the basic and intermediate topics of this programming language such as data types, variables, operators, control structures, functions, and classes.
We hope you enjoyed taking those questions and learned something new or refreshed your memory of C++.
Check MCQ on C++ (Part-1)
In this post, we will continue with some more MCQs on C++ that cover similar topics from the basic to the intermediate level.
As before, Each question has 4 multiple choices, out of which only 1 is correct. If you click on the correct answer, you will see a green check mark, and if you click on the wrong answer, you will see a red cross mark.
MCQ on C++ (Part-2)
Question 1: Which of the following is a correct way to declare and define a function in C++?
Question 2: What is the output of the following code snippet?
int x = 10;
int y = 5;
x += y++;
std::cout << x << std::endl;
Question 3: What is the purpose of the "break" statement in a switch statement?
Question 4: What is the purpose of the "new" operator in C++?
Question 5: Which of the following is NOT a valid storage class specifier in C++?
Question 6: Which of the following is true about the "friend" keyword in C++?
Question 7: What is the purpose of the "this" pointer in C++?
Question 8: What is the purpose of the "virtual" keyword in C++?
Question 9: Which of the following is true about C++ templates?
Question 10: What is the output of the following code snippet?
int x = 5;
int* p = &x;
std::cout << *p << std::endl;
Question 11: Which of the following is true about function overloading in C++?
Question 12: What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
std::cout << *ptr << std::endl;
Question 13: Which operator is used to access the member functions and variables of objects in C++?
Question 14: What is the purpose of the "const" keyword in C++?
Question 15: Which of the following is a valid way to pass arguments to a C++ function?
Question 16: What is the output of the following code snippet?
int x = 5;
int& ref = x;
ref = 10;
std::cout << x << std::endl;
Question 17: Which keyword is used to explicitly convert one data type to another in C++?
Question 18: Which of the following is true about static member variables in C++?
Question 19: Which of the following statements is true about the "new" operator in C++?
Question 20: What is the purpose of the "virtual" keyword in C++?
Question 21: What is the purpose of the "this" pointer in C++?
Question 22: What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr + 2;
std::cout << *ptr << std::endl;
Question 23: What is the purpose of the "inline" keyword in C++?
Question 24: What is the difference between "delete" and "delete[]" operators in C++?
Question 25: What is the output of the following code snippet?
class Base {
public:
Base() { std::cout << "Base constructor" << std::endl; }
virtual ~Base() { std::cout << "Base destructor" << std::endl; }
};
class Derived : public Base {
public:
Derived() { std::cout << "Derived constructor" << std::endl; }
~Derived() { std::cout << "Derived destructor" << std::endl; }
};
int main() {
Base* ptr = new Derived();
delete ptr;
return 0;
}
Question 26: Which keyword is used to indicate that a class cannot be inherited from?
Question 27: What does the "const" qualifier indicate in C++?
Question 28: What is the purpose of the "new" operator in C++?
Question 29: What is the purpose of the "friend" keyword in C++?
Question 30: What is the purpose of the "using" directive in C++?
The Bottom Line
We hope you found these MCQs on C++ (Part-2) useful and fun.
If you did, please share this with your friends or colleagues who might be interested in C++.
Also, stay tuned for our next blog post.

Abdur Rohman is an Electrical Engineer from Charaideo, Assam, who wears multiple hats as a part-time teacher, blogger, entrepreneur, and digital marketer. Passionate about education, he founded The Assam School blog to provide free, comprehensive textbook solutions, MCQs (Multiple Choice Questions), and other academic content for students from Class V to XII.