Learn C++ MCQs

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

Which of the following allows a function to be defined inline in C++?

1) inline

2) static

3) extern

4) const

Answer : Option 1

What will be the output of cout << (15 / 3 + 2 * 4) << endl;

1) 10

2) 14

3) 8

4) None of the above

Answer : Option 1

Which of the following is not an access specifier in C++?

1) public

2) private

3) protected

4) internal

Answer : Option 4

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

1) 2

2) 3

3) 1

4) None of the above

Answer : Option 4

What is the correct way to define a class in C++?

1) class MyClass {};

2) class MyClass;

3) class MyClass() {}

4) None of the above

Answer : Option 1

Which of the following is used to allocate memory dynamically in C++?

1) malloc()

2) new

3) calloc()

4) All of the above

Answer : Option 2

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

1) 14

2) 10

3) 6

4) None of the above

Answer : Option 1

Which of the following is the correct way to create an object in C++?

1) MyClass obj;

2) MyClass* obj = new MyClass();

3) Both 1 and 2

4) None of the above

Answer : Option 3

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

1) 3

2) 3.5

3) 4

4) None of the above

Answer : Option 1

Which of the following is a member function of the string class in C++?

1) size()

2) length()

3) substr()

4) All of the above

Answer : Option 4