Skills101
← All practice quizzes

Quiz: C++ Interview Questions

5 questionsNo time limitPass: 60%+10 XP on first pass

The C++ questions asked in campus interviews and written tests: C vs C++, references, virtual functions, constructors, the STL, memory — plus tricky output programs, each compiled and explained.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is printed?

    #include <iostream>
    using namespace std;
    struct P { P() { cout << "P"; } ~P() { cout << "p"; } };
    struct C : P { C() { cout << "C"; } ~C() { cout << "c"; } };
    int main() { C x; return 0; }
    
  2. Question 2

    Which is the only default difference between struct and class?

  3. Question 3

    What problem does a shallow copy of a class with a raw pointer cause?

  4. Question 4

    What does this print?

    #include <iostream>
    using namespace std;
    int main() {
        int x = 10;
        int &y = x;
        y++;
        x *= 2;
        cout << y;
        return 0;
    }
    
  5. Question 5

    What does new do that malloc doesn't?