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 : void MyClass() {}

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

1) 1

2) 0

3) true

4) false

Answer : 1

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

1) public

2) private

3) protected

4) None of the above

Answer : private

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

1) template <typename T> void func(T arg) {}

2) template <T> void func(T arg) {}

3) void func(template <typename T> T arg) {}

4) None of the above

Answer : template <typename T> void func(T arg) {}

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

1) 1

2) 0

3) 3

4) 2

Answer : 1

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

1) int*

2) int&

3) void*

4) char*

Answer : int&

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 : dynamic_cast

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 : Both 1 and 2

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 : union MyUnion { int x; float y; };