Topic / 110 questions

C++ MCQs

C++ MCQs test your understanding of the C++ language, including classes, constructors, pointers, inheritance and exception handling. They help computer science students and software job applicants check their basics, and every question shows its correct answer immediately so you can fix gaps before an exam or interview.

Question 03 C++

What is wrong with the function int& getValue() { int local = 5; return local; }?

Correct answer A. It returns a reference to a local variable that is destroyed when the function returns

Open question
Advertisement
Advertisement
Question 10 C++

What is the core idea of RAII (Resource Acquisition Is Initialisation) in C++?

Correct answer C. A resource is tied to an object's lifetime, acquired in its constructor and released in its destructor

Open question
Question 11 C++

Why are C++ function and class template definitions normally placed in header files?

Correct answer D. Because the full definition must be visible wherever the template is instantiated

Open question
Question 14 C++

Why is writing using namespace std; in a header file considered bad practice?

Correct answer C. It forces every file that includes the header to import all std names, risking name clashes

Open question
Advertisement
Question 17 C++

Why is operator<< for printing a user-defined type to std::ostream usually written as a non-member (often friend) function?

Correct answer B. Because the left operand is the ostream, not an object of the user's class

Open question
Question 20 C++

What does std::move actually do to its argument?

Correct answer D. It casts it to an rvalue reference so move operations can be selected

Open question

About C++ MCQs

This topic covers object-oriented C++ concepts that written tests often check. Questions ask which keywords generate and handle exceptions, namely try, throw and catch, and how code reusability is achieved through inheritance. You will see that a default constructor takes no arguments, that class members are private by default unlike struct members, and that an uninitialised pointer is called a wild pointer. Other items deal with declaring a pointer more than once and basic syntax rules. These points come up in computer science lecturer tests, software house screening tests and placement rounds.

Exams that include C++ MCQs

Pakistan

  • NTS
  • PPSC
  • FPSC
  • Lecturer tests

India

  • Campus placements
  • UGC NET
  • SSC CGL

Bangladesh

  • Government job tests
  • Bank job exams
  • BCS

Frequently asked questions

What is the default access specifier for class members in C++?

Members of a class in C++ are private by default, so they cannot be accessed from outside the class unless declared public or protected. In a struct, members are public by default. This difference is one of the most common C++ MCQ topics.

What is a wild pointer in C++?

A wild pointer is a pointer that has been declared but not initialised, so it holds an unpredictable address. Using it can crash a program or corrupt memory. Good practice is to initialise pointers to nullptr or to a valid address when they are declared.

Last reviewed October 2026