← C++ Programming and OOP: From Variables to Classes and the STL

Click “Download PDF”, then choose “Save as PDF” as the printer.

VJ Classes

MCQs with answers

C++ Programming and OOP: From Variables to Classes and the STL

1. Which header must you include to use cout and cin?

  1. A. string
  2. B. vector
  3. C. iostream
  4. D. cstdio

2. Which of these is a valid variable name in C++?

  1. A. total_marks
  2. B. 2nd_year
  3. C. my-score
  4. D. class

3. Which loop always runs its body at least once, even when the condition is false from the start?

  1. A. for
  2. B. while
  3. C. range-based for
  4. D. do-while

4. The vector of int named v holds 40, 10, 30, 20 in that order. After sort(v.begin(), v.end()), what is v[1]?

  1. A. 10
  2. B. 20
  3. C. 30
  4. D. 40

5. After the statements int x = 7; x += 3; x *= x; x %= 7; what is x?

  1. A. 0
  2. B. 3
  3. C. 2
  4. D. 14

6. int n = 2; switch (n) { case 1: cout << "A"; case 2: cout << "B"; case 3: cout << "C"; break; default: cout << "D"; } What is printed?

  1. A. BC
  2. B. B
  3. C. BCD
  4. D. ABC

7. A function is defined as void doubleIt(int& a) { a = a * 2; }. In main, int n = 4; and then doubleIt(n); is called twice. What is n?

  1. A. 4
  2. B. 8
  3. C. 16
  4. D. 32

8. A class Account has only one constructor, Account(string name, double opening). Which line fails to compile?

  1. A. Account a("Ravi", 500);
  2. B. Account b = Account("Imran", 0);
  3. C. Account c("Meena", 1200.50);
  4. D. Account d;

9. Two vectors of int are created: a(3, 7) with parentheses and b{3, 7} with braces. Which statement is true?

  1. A. a holds the three values 7, 7, 7 and b holds the two values 3 and 7
  2. B. a holds the two values 3 and 7 and b holds the three values 7, 7, 7
  3. C. Both hold the two values 3 and 7
  4. D. Both hold three copies of 7

10. Shape has a pure virtual function area(). The class Square derives from Shape but does not override area(). What happens if main tries to create a Square object?

  1. A. It compiles, and area() returns 0
  2. B. The compiler reports an error, because Square is still abstract
  3. C. It compiles, but the program crashes when area() is called
  4. D. It compiles, and area() returns a random value

Answer key

© 2026 VJ Classes · vjclasses.in