c++ programming banner

C++ Programming Multiple Choice Questions (MCQs) and Answers

Master C++ Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of C++ Programming. Begin your placement preparation journey now!

Q1

Q1 What is an object in object-oriented programming?

A

A code snippet

B

A variable

C

An instance of a class

D

A function

Q2

Q2 Which of the following is a feature of procedure-oriented programming?

A

Class-based

B

Focus on functions

C

Inheritance

D

Polymorphism

Q3

Q3 In OOP, what does encapsulation refer to?

A

Storing data in arrays

B

The process of inheritance

C

Combining data and methods

D

A type of loop

Q4

Q4 Which principle of OOP is illustrated by defining different methods with the same name but different parameters?

A

Inheritance

B

Polymorphism

C

Encapsulation

D

Abstraction

Q5

Q5 What distinguishes a class from an object in OOP?

A

A class is a blueprint, while an object is an instance of a class

B

A class cannot contain methods, while an object can

C

Objects are templates, while classes are real entities

D

There is no difference

Q6

Q6 Which concept in OOP allows for the same function to be used in different ways based on the object it is associated with?

A

Encapsulation

B

Abstraction

C

Inheritance

D

Polymorphism

Q7

Q7 Consider the following code snippet:
class Animal { public: void eat() { cout << "Eating..."; } };
What is demonstrated in this code?

A

Inheritance

B

Encapsulation

C

Class definition

D

Polymorphism

Q8

Q8 Identify the issue in this C++ code snippet:
class Car {
public:
int speed;
void Car() { speed = 0; }
};

A

Incorrect class constructor syntax

B

Missing data encapsulation

C

No error

D

Inheritance misuse

Q9

Q9 What is the role of comments in a C++ program?

A

To optimize code execution

B

To define variables

C

To provide documentation and explanation

D

To declare constants

Q10

Q10 Which of these is not a fundamental data type in C++?

A

int

B

float

C

string

D

char

Q11

Q11 What is a variable in C++?

A

A constant value

B

A data type

C

A storage location with a name

D

A keyword

Q12

Q12 Which data type would be best to store a person's age?

A

int

B

double

C

bool

D

char

Q13

Q13 What is a constant in C++?

A

A variable whose value can change

B

A fixed value that cannot be altered during execution

C

A type of operator

D

A special function

Q14

Q14 What is the output of this C++ code?
int main() {
int x = 5;
cout << x;
return 0;
}

A

0

B

5

C

x

D

Error

Q15

Q15 Identify the error in this C++ code:
int main() {
int 123number;
return 0;
}

A

Variable name starting with a digit

B

Incorrect data type

C

Syntax error in return statement

D

No error

Q16

Q16 Spot the error in this C++ code:
const int num; num = 10;
cout << num;

A

Missing variable initialization

B

Incorrect use of const

C

Syntax error in cout statement

D

No error

Q17

Q17 What is the output of the expression 5 + 3 * 2 in C++?

A

16

B

11

C

10

D

8

Q18

Q18 Which operator is used for logical AND in C++?

A

&&

B

&

C

||

D

==

Q19

Q19 What does the ++ operator do in C++?

A

Divides the value by two

B

Decreases the value by one

C

Increases the value by one

D

Squares the value

Q20

Q20 In C++, what is the difference between == and =?

A

== is used for assignment, while = is used for comparison

B

== is used for comparison, while = is used for assignment

C

Both are used for assignment

D

Both are used for comparison

Q21

Q21 What is the result of the expression !true && false in C++?

A

true

B

false

C

Syntax error

D

None of the above

Q22

Q22 What is the output of the following code?
int a = 1;
int b = 2;
cout << (a++ + b);

A

3

B

4

C

Syntax error

D

2

Q23

Q23 What is the result of int x = 10; x *= 3; in C++?

A

30

B

13

C

33

D

10

Q24

Q24 Pseudocode:

SET a TO 5 IF a > 3 THEN PRINT "Yes" ELSE PRINT "No" What is the output?

A

Yes

B

No

C

Error

D

None

Q25

Q25 Pseudocode:

SET x TO 10 SET y TO x MOD 4 PRINT y What does this print?

A

2

B

4

C

10

D

0

Q26

Q26 Pseudocode:

SET val TO 7 IF val < 10 AND val > 5 THEN PRINT "In range" ELSE PRINT "Out of range" What is the output?

A

In range

B

Out of range

C

Error

D

None

Q27

Q27 Pseudocode:

SET num TO 15 SET result TO num DIV 2 PRINT result What does this print?

A

7.5

B

7

C

15

D

Error

Q28

Q28 Pseudocode:

IF (5 > 3) OR (8 < 6) THEN PRINT "True" ELSE PRINT "False" What is the output?

A

True

B

False

C

Error

D

None

Q29

Q29 Find the mistake:
int num;
num == 5;
cout << num;

A

Misuse of equality operator

B

Undeclared variable

C

No error

D

Syntax error in cout statement

Q30

Q30 Identify the error:
int x = 10;
int y = ++x + 2;
cout << x << " " << y;

A

Incorrect use of increment operator

B

No error

C

Syntax error in cout statement

D

Misuse of assignment operator

ad verticalad vertical
ad