Learn C++ MCQs

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

Which of the following is not a valid constructor in C++?

1) MyClass() {}

2) MyClass(int) {}

3) MyClass(int, int) {}

4) void MyClass() {}

Answer : Option 4

What will be the output of cout << (3 == 3) << endl;

1) 1

2) 0

3) true

4) false

Answer : Option 1

What is the default access specifier for class members in C++?

1) public

2) private

3) protected

4) None of the above

Answer : Option 2

Which of the following is a correct syntax for a template function?

1) template void func(T arg) {}

2) template void func(T arg) {}

3) void func(template T arg) {}

4) None of the above

Answer : Option 1

What is the output of cout << (7 % 2) << endl;

1) 1

2) 0

3) 3

4) 2

Answer : Option 1

Which of the following is not a valid pointer type in C++?

1) int*

2) int&

3) void*

4) char*

Answer : Option 2

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

1) 1

2) 0

3) true

4) false

Answer : Option 2

Which operator is used for typecasting in C++?

1) as

2) cast

3) dynamic_cast

4) None of the above

Answer : Option 3

What is the correct way to declare a constant variable in C++?

1) const int x = 10;

2) int const x = 10;

3) Both 1 and 2

4) None of the above

Answer : Option 3

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

1) union MyUnion { int x; float y; };

2) union { int x; float y; };

3) MyUnion { union int x; float y; };

4) None of the above

Answer : Option 1