Learn C++ MCQs

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

Which of the following is used for input in C++?

1) cin

2) scanf

3) getline

4) All of the above

Answer : Option 1

What is the output of cout << (5 && 0) << endl;

1) 1

2) 0

3) 5

4) None of the above

Answer : Option 2

Which of the following is the correct way to declare a class member function?

1) void MyClass::func() {}

2) MyClass::func() {}

3) void func() {}

4) func() MyClass {}

Answer : Option 1

What is the output of cout << (8 >> 1) << endl;

1) 4

2) 8

3) 1

4) None of the above

Answer : Option 1

Which of the following is the correct way to allocate memory for an object in C++?

1) MyClass *obj = new MyClass();

2) MyClass obj = new MyClass();

3) MyClass *obj; obj = new MyClass;

4) None of the above

Answer : Option 1

What is the output of cout << (10 / 4) << endl;

1) 2

2) 2.5

3) 3

4) None of the above

Answer : Option 1

Which of the following is the correct way to define a template function in C++?

1) template void func(T t) {}

2) void func(T t) {}

3) template void func(T t) {}

4) None of the above

Answer : Option 1

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

1) 11

2) 10

3) 14

4) None of the above

Answer : Option 1

Which of the following keywords is used to inherit a class in C++?

1) extends

2) implements

3) inherits

4) public

Answer : Option 4

What will be the output of the following code: cout << (2 + 3 * 4) << endl;

1) 14

2) 20

3) 16

4) None of the above

Answer : Option 1