Learn C++ MCQs

Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following is the correct way to declare an inline function?

1) inline int func() {}

2) int inline func() {}

3) inline func() int {}

4) None of the above

Answer : Option 1

What is the output of cout << (3 & 1) << endl;

1) 1

2) 0

3) 3

4) None of the above

Answer : Option 1

Which of the following is not a feature of OOP?

1) Encapsulation

2) Abstraction

3) Compilation

4) Inheritance

Answer : Option 3

What will be the output of cout << (true || false) << endl;

1) 1

2) 0

3) true

4) false

Answer : Option 1

What is the purpose of the `friend` keyword in C++?

1) To declare a function as a friend

2) To allow access to private members

3) Both 1 and 2

4) None of the above

Answer : Option 3

What is the output of cout << (2 * 3 + 5) << endl;

1) 11

2) 10

3) 12

4) None of the above

Answer : Option 1

Which of the following is used to exit from a loop in C++?

1) break

2) exit

3) continue

4) return

Answer : Option 1

What is the correct way to initialize a vector in C++?

1) vector v;

2) vector v;

3) vector v = {};

4) None of the above

Answer : Option 1

What will be the output of cout << (3 * 5 < 20) << endl;

1) 1

2) 0

3) True

4) False

Answer : Option 1

Which of the following is the correct way to define a destructor?

1) ~MyClass() {}

2) MyClass::~MyClass() {}

3) MyClass() ~{}

4) None of the above

Answer : Option 1