an HCL GUVI product

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!

Q91

Q91 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

Q92

Q92 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

Q93

Q93 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

Q94

Q94 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

Q95

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

A

012

B

123

C

Nothing

D

Error

Q96

Q96 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

Q97

Q97 Pseudocode:

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

A

012

B

123

C

Error

D

Nothing

Q98

Q98 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

Q99

Q99 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

Q100

Q100 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

Q101

Q101 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

Q102

Q102 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

Q103

Q103 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

Q104

Q104 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

Q105

Q105 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

Q106

Q106 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

Q107

Q107 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

Q108

Q108 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

Q109

Q109 In C++, how can you initialize an array of integers named 'num' with the first four natural numbers?

A

int num[] = {1, 2, 3, 4};

B

int num[4] = {1, 2, 3, 4};

C

int num[4] = {1, 2, 3};

D

int num[] = {1, 2, 3, 4, 5};

Q110

Q110 Which statement is true about passing an array to a function in C++?

A

The array is always passed by value

B

The array is always passed by reference

C

A copy of the array is created

D

The size of the array must be known to the function

Q111

Q111 What is the output of this code?
int arr[] = {1, 2, 3};
cout << arr[1];

A

1

B

2

C

3

D

Error

Q112

Q112 Consider the code:
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};
cout << matrix[1][1];
What does it print?

A

1

B

2

C

5

D

6

Q113

Q113 What is the output of the following code?
char chars[] = {'A', 'B', 'C', '\0'};
cout << chars;

A

A

B

AB

C

ABC

D

ABCD

Q114

Q114 Pseudocode:

SET matrix[2][2] TO [[1, 2], [3, 4]] PRINT matrix[0][1] What is the output?

A

1

B

2

C

3

D

4

Q115

Q115 Pseudocode:

SET charArray TO ['H', 'e', 'l', 'l', 'o', '\0'] PRINT charArray What is printed?

A

H

B

Hello

C

ello

D

Helloworld

Q116

Q116 Identify the error in this code:
int arr[3];
arr[3] = 10;
cout << arr[3];

A

Out of bounds array access

B

Syntax error

C

Type mismatch

D

No error

Q117

Q117 How do you declare a pointer to an integer in C++?

A

int *ptr;

B

int &ptr;

C

int ptr[];

D

int ptr;

Q118

Q118 What does the dereference operator (*) do in C++?

A

It multiplies two values

B

It returns the address of a pointer

C

It accesses the value at the address a pointer is pointing to

D

It creates a pointer

Q119

Q119 What is the output of the following code?
int x = 10;
int *ptr = &x;
cout << *ptr;

A

10

B

&x

C

ptr

D

*ptr

Q120

Q120 Pseudocode:

SET x TO 20 SET ptr TO ADDRESS OF x PRINT VALUE AT ptr What does this print?

A

20

B

ADDRESS OF x

C

ptr

D

VALUE AT ptr

ad vertical