Assuming standard headers and using namespace std, what does this C++ code print? auto p = make_shared<int>(7); auto q = p; { auto r = p; cout << p.use_count(); } cout << p.use_count();
Correct answer B. 32
Topic / 110 questions
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.
Correct answer B. 32
Correct answer B. std::nullptr_t
Correct answer A. It returns a reference to a local variable that is destroyed when the function returns
Correct answer B. AB
Correct answer B. delete[] p;
Correct answer A. A reference to *this, of type X&
Correct answer A. 1
Correct answer A. 111 103
Correct answer A. Only members declared mutable
Correct answer C. A resource is tied to an object's lifetime, acquired in its constructor and released in its destructor
Correct answer D. Because the full definition must be visible wherever the template is instantiated
Correct answer C. BD~D~B
Correct answer D. 234
Correct answer C. It forces every file that includes the header to import all std names, risking name clashes
Correct answer A. 6 7
Correct answer B. It returns a null pointer
Correct answer B. Because the left operand is the ostream, not an object of the user's class
Correct answer C. 7 2.5
Correct answer C. 19
Correct answer D. It casts it to an rvalue reference so move operations can be selected
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.
Pakistan
India
Bangladesh
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.
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