C++ Programming MCQs & Mock Tests

Topic-wise bilingual C++ questions for college exams, GATE, interviews, and competitive tests.

Q1 · C++ Fundamentals & OperatorsBeginner

Which operator in C++ is used to dynamically allocate memory on the heap for a single object?

Q2 · C++ Fundamentals & OperatorsBeginner

What will be the output of the following C++ snippet?

int a = 7, b = 2;
std::cout << static_cast<double>(a) / b;
Q3 · C++ Fundamentals & OperatorsBeginner

Which literal is type-safe for representing a null pointer in Modern C++ (C++11+)?

Q4 · Pointers, References & MemoryIntermediate

Which smart pointer enforces exclusive ownership and cannot be copied?

Q5 · Pointers, References & MemoryBeginner

What is true about C++ references compared to pointers?

Q6 · OOP, Inheritance & PolymorphismIntermediate

Why should a polymorphic base class declare a virtual destructor?

class Base {
public:
    virtual ~Base() = default;
};
Q7 · OOP, Inheritance & PolymorphismIntermediate

Which keyword solves the Diamond Problem in C++ multiple inheritance?

Q8 · STL, Templates & Modern C++Intermediate

What is the average time complexity of lookup in std::unordered_map?

Q9 · STL, Templates & Modern C++Advanced

Which C++17 type represents a value that may or may not be present without heap allocation?

Q10 · Lambdas & Functional C++Intermediate

Which C++ standard introduced lambda expressions, and which introduced generic `auto` lambda parameters?

Q11 · Lambdas & Functional C++Intermediate

What happens when a `mutable` lambda modifies a value-captured variable `count`?

int count = 0;
auto fn = [count]() mutable { return ++count; };
Q12 · Lambdas & Functional C++Advanced

Which lambda can be implicitly converted into an ordinary C/C++ function pointer?