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!

Q31

Q31 What is the purpose of the if statement in C++?

A

To execute a block of code multiple times

B

To stop the execution of the program

C

To make a decision

D

To declare a variable

Q32

Q32 Which control flow statement is used for executing a block of code repeatedly based on a condition?

A

if

B

else

C

for

D

switch

Q33

Q33 What is the function of the break statement in a loop?

A

To pause the loop

B

To skip an iteration of the loop

C

To terminate the loop

D

To continue to the next iteration of the loop

Q34

Q34 In C++, the do-while loop is unique because it...

A

executes its block of code at least once

B

is faster than other loops

C

does not check a condition

D

can only run a fixed number of times

Q35

Q35 What is the primary difference between a for loop and a while loop in C++?

A

Syntax only

B

While loop can run infinitely, for loop cannot

C

For loop is used for arrays, while loop is not

D

Initialization, condition checking, and increment/decrement are part of the for loop statement

Q36

Q36 What happens if the condition in an if statement is false?

A

The program terminates

B

The else part is executed

C

The program skips to the next loop

D

None of the above

Q37

Q37 What is the output of this code?
int i = 0;
while(i < 3) {
cout << i; i++;
}

A

012

B

123

C

Infinite loop

D

Syntax error

Q38

Q38 Consider the code:
for(int i = 0; i <= 2; i++) {
cout << i;
}.
What does it print?

A

012

B

123

C

Nothing

D

Error

Q39

Q39 What is the output of the following code?
int x = 10;
do {
cout << x;
x--; } while (x > 10);

A

Prints 10 once

B

Prints 10 and then 9

C

Prints numbers from 10 to 1

D

No output

Q40

Q40 Pseudocode:

IF x > 10 THEN PRINT "Greater" ELSE PRINT "Smaller or Equal" If x is 8, what is printed?

A

Greater

B

Smaller or Equal

C

Error

D

Nothing

Q41

Q41 Pseudocode:

SET i TO 0 WHILE i < 3 DO PRINT i INCREMENT i What does this print?

A

012

B

123

C

Infinite loop

D

Nothing

Q42

Q42 Pseudocode:

FOR i FROM 0 TO 2 DO PRINT i What is the output?

A

012

B

123

C

Error

D

Nothing

Q43

Q43 Pseudocode:

SET count TO 0 REPEAT PRINT count INCREMENT count UNTIL count EQUALS 5 What is the output?

A

01234

B

012345

C

Infinite loop

D

Error

Q44

Q44 Identify the error in the code:
int i = 1;
for(; i <= 5; i++) {
cout << i;
}

A

Missing initialization in for loop

B

No error

C

Syntax error in cout statement

D

Incorrect loop condition

Q45

Q45 Spot the mistake:
int num = 0;
do {
cout << num;
} while(num);

A

Infinite loop

B

Syntax error

C

Should use a for loop

D

No error

Q46

Q46 What is a function prototype in C++?

A

A function that always returns an integer

B

The first call to a function in a program

C

A declaration of a function before its definition

D

A function without arguments

Q47

Q47 What is function overloading in C++?

A

Calling a function multiple times

B

Defining multiple functions with the same name but different parameters

C

Defining a function inside another function

D

Using default arguments in a function

Q48

Q48 What is the purpose of default arguments in function definitions?

A

To specify what value a function returns

B

To give a default value to a parameter if no argument is passed

C

To make a parameter optional

D

To overload a function

Q49

Q49 In C++, what is recursion?

A

A function calling another function

B

A function that calls itself

C

Repeatedly executing a loop

D

A type of data structure

Q50

Q50 How does a recursive function in C++ stop calling itself?

A

By using a for loop

B

By reaching a return statement

C

Through a conditional statement that leads to a return

D

By calling another function

Q51

Q51 What does this function do?
void printHello() {
cout << "Hello, World!";
}

A

Prints "Hello, World!" to the console repeatedly

B

Prints "Hello, World!" once to the console

C

Does nothing

D

Causes a runtime error

Q52

Q52 What is the output of this function call?
int add(int x, int y = 5) {
return x + y;
} cout << add(3);

A

8

B

3

C

5

D

Syntax error

Q53

Q53 Consider the function:
int multiply(int x, int y) { return x * y; }
What is returned by multiply(5, 4);?

A

20

B

9

C

Syntax error

D

0

Q54

Q54 Pseudocode:

FUNCTION AddNumbers(x, y) RETURN x + y END What does this function do?

A

Adds two numbers and prints the result

B

Subtracts two numbers

C

Adds two numbers and returns the result

D

Multiplies two numbers

Q55

Q55 Pseudocode:

FUNCTION PrintMessage() PRINT "Hello" END What is the purpose of this function?

A

To return the string "Hello"

B

To print "Hello" to the console

C

To store the message "Hello"

D

To check if "Hello" is printed

Q56

Q56 Pseudocode:

FUNCTION FindMax(x, y) IF x > y THEN RETURN x ELSE RETURN y END What does this function return?

A

The sum of x and y

B

The smaller of x and y

C

The larger of x and y

D

Nothing if x equals y

Q57

Q57 Pseudocode:

FUNCTION CalculateFactorial(n) IF n <= 1 THEN RETURN 1 ELSE RETURN n * CalculateFactorial(n - 1) END What does this function calculate?

A

The sum of numbers up to n

B

The factorial of n

C

The product of n and n-1

D

The nth number in the Fibonacci sequence

Q58

Q58 Find the error in this function:
int square(int n) {
return n * n;
}
cout << square();

A

Missing argument in function call

B

Syntax error in return statement

C

No return type for function

D

No error

Q59

Q59 Identify the mistake in this code:
void printNum(int number = 5) {
cout << number;
}
printNum(10, 5);

A

Incorrect number of arguments

B

No error

C

Syntax error in function definition

D

Error in default argument

Q60

Q60 What is an array in C++?

A

A collection of variables of different types

B

A single variable that can store multiple values

C

A function that returns multiple values

D

A data structure that allows recursion

ad verticalad vertical
ad