31
How do you declare a multidimensional array with 3 rows and 4 columns in C++?
A)
int arr[3][4] = {0};
B)
int arr[3, 4];
C)
int arr[][] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12} }
D)
int arr[3][4];
Answer & Solution
Answer: Option
D
32
What is the output of the following code: char str[10]; cout << sizeof(str); in C++?
A)
9
B)
11
C)
10
D)
Compilation error
Answer & Solution
Answer: Option
C
33
Which function is used to find the first occurrence of a specified substring within a string in C++?
A)
strfind()
B)
strstr()
C)
substr()
D)
None of the above
Answer & Solution
Answer: Option
B
34
What is the output of the following code: char str[] = "Hello"; cout << str[0] << str[4]; in C++?
A)
Undefined behavior
B)
Compilation error
C)
Ho
D)
ello
Answer & Solution
Answer: Option
C
35
In C++, what is the purpose of the 'cin.getline()' function?
A)
Reads a character from standard input
B)
Reads a word from standard input
C)
Reads a string from standard input
D)
Reads a line of text from standard input
Answer & Solution
Answer: Option
D
36
How do you declare a string object named 'text' in C++?
A)
string text;
B)
string text();
C)
string text{};
D)
string text = "";
Answer & Solution
Answer: Option
A
37
What is the correct syntax for declaring an array of 5 integers in C++?
A)
int arr{} = {1, 2, 3, 4, 5};
B)
int[] arr = new int[5];
C)
int arr[] = {1, 2, 3, 4, 5};
D)
int arr[5];
Answer & Solution
Answer: Option
D
38
What is the purpose of the 'cin.ignore()' function in C++?
A)
Ignores the next character in the input buffer
B)
Ignores the previous character in the input buffer
C)
Clears the input buffer
D)
Reads a character from the input buffer and discards it
Answer & Solution
Answer: Option
C
39
What is the output of the following code: char str[] = "Hello"; cout << strlen(str); in C++?
A)
Hello
B)
5
C)
Compilation error
D)
Runtime error
Answer & Solution
Answer: Option
B
40
What is the correct syntax to declare a string literal in C++?
A)
const char* str = "Hello";
B)
string str = "Hello";
C)
char* str = "Hello";
D)
char str[] = "Hello";
Answer & Solution
Answer: Option
A