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!

Q61

Q61 How do you access the third element in an array named 'arr' in C++?

A

arr[2]

B

arr[3]

C

arr(2)

D

arr(3)

Q62

Q62 What are multidimensional arrays in C++?

A

Arrays with only one row or column

B

Arrays with more than one dimension, like 2D or 3D arrays

C

Arrays containing elements of different data types

D

Dynamic arrays

Q63

Q63 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};

Q64

Q64 What is the size of a character array initialized as char arr[] = "Hello";?

A

4

B

5

C

6

D

7

Q65

Q65 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

Q66

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

A

1

B

2

C

3

D

Error

Q67

Q67 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

Q68

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

A

A

B

AB

C

ABC

D

ABCD

Q69

Q69 Pseudocode:

SET arr[3] TO [10, 20, 30] PRINT arr[0] What does this print?

A

10

B

20

C

30

D

0

Q70

Q70 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

Q71

Q71 Pseudocode:

SET nums[5] TO [1, 2, 3, 4, 5] FOR EACH num IN nums DO PRINT num What does this print?

A

12345

B

54321

C

15

D

Error

Q72

Q72 Pseudocode:

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

A

H

B

Hello

C

ello

D

Helloworld

Q73

Q73 Pseudocode:

SET arr[3] TO [0] FOR i FROM 0 TO 2 DO SET arr[i] TO i + 1 END PRINT arr[2] What is the output?

A

1

B

2

C

3

D

0

Q74

Q74 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

Q75

Q75 Spot the mistake:
int nums[] = {1, 2, 3};
for(int i = 0; i <= 3; i++) {
cout << nums[i];
}

A

Incorrect loop condition

B

Missing array initialization

C

No error

D

Syntax error in cout statement

Q76

Q76 Find the error in this code:
char str[5]; str = "Hello";
cout << str;

A

Invalid assignment to char array

B

No error

C

Syntax error in cout statement

D

Array size mismatch

Q77

Q77 What is a pointer in C++?

A

A variable that stores the address of another variable

B

A reference to another variable

C

A type of array

D

A function parameter

Q78

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

A

int *ptr;

B

int &ptr;

C

int ptr[];

D

int ptr;

Q79

Q79 What is the purpose of the reference operator (&) in C++?

A

To create a reference variable

B

To access the address of a variable

C

To dereference a pointer

D

To perform bitwise AND

Q80

Q80 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

Q81

Q81 How are arrays and pointers related in C++?

A

Pointers can only point to the first element of an array

B

Arrays and pointers are fundamentally different

C

An array name can be used as a pointer to its first element

D

Pointers cannot be used to access array elements

Q82

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

A

10

B

&x

C

ptr

D

*ptr

Q83

Q83 Given the code
int arr[] = {1, 2, 3};
int *ptr = arr;
cout << ptr[1];,
what is the output?

A

1

B

2

C

3

D

&arr[1]

Q84

Q84 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

Q85

Q85 Pseudocode:

SET arr TO [10, 20, 30] SET ptr TO ADDRESS OF arr[0] PRINT ptr[2] What is the output?

A

10

B

20

C

30

D

ADDRESS OF arr[2]

Q86

Q86 Identify the error in this code:
int x = 5;
int *ptr;
*ptr = &x;
cout << *ptr;

A

Incorrect assignment to pointer

B

Syntax error

C

No error

D

Dereferencing an uninitialized pointer

Q87

Q87 Find the mistake:
int num = 10;
int &ref = num;
ref = nullptr;
cout << num;

A

Assigning nullptr to a reference

B

Syntax error

C

No error

D

Incorrect initialization of the reference

Q88

Q88 What is a class in C++?

A

A blueprint for creating objects

B

A function in OOP

C

A variable type

D

An operator

Q89

Q89 What is inheritance in OOP?

A

The process of acquiring properties from one class to another

B

Copying of methods between classes

C

Linking of two classes

D

Creating new classes

Q90

Q90 What does encapsulation in C++ refer to?

A

The process of combining data and functions into a single unit

B

Creating multiple copies of the same function

C

Protecting data by making it private

D

Linking different classes together

ad verticalad vertical
ad