Software Development Exam  >  Software Development Tests  >  Basics of C++  >  Test: Strings - 2 - Software Development MCQ

Test: Strings - 2 - Software Development MCQ


Test Description

20 Questions MCQ Test Basics of C++ - Test: Strings - 2

Test: Strings - 2 for Software Development 2024 is part of Basics of C++ preparation. The Test: Strings - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Strings - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Strings - 2 below.
Solutions of Test: Strings - 2 questions in English are available as part of our Basics of C++ for Software Development & Test: Strings - 2 solutions in Hindi for Basics of C++ course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Strings - 2 | 20 questions in 40 minutes | Mock test for Software Development preparation | Free important questions MCQ to study Basics of C++ for Software Development Exam | Download free PDF with solutions
Test: Strings - 2 - Question 1

Which of the following is the correct way to declare a string variable in C++?

Detailed Solution for Test: Strings - 2 - Question 1

'string s;' is the correct way to declare a string variable in C++.

Test: Strings - 2 - Question 2

Which of the following is not a valid method to concatenate two strings in C++?

Detailed Solution for Test: Strings - 2 - Question 2

Using the 'concat()' function is not a valid method to concatenate two strings in C++.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Strings - 2 - Question 3

What is the output of the following code snippet?
string s = "Hello World";
cout << s.length() << endl;

Detailed Solution for Test: Strings - 2 - Question 3

The output of the code snippet is 11 because 's.length()' returns the length of the string, which is 11 in this case.

Test: Strings - 2 - Question 4

Which of the following string functions can be used to find the first occurrence of a character in a string?

Detailed Solution for Test: Strings - 2 - Question 4

The 'find_first_of()' function can be used to find the first occurrence of a character in a string.

Test: Strings - 2 - Question 5

Which of the following functions can be used to convert a string to uppercase in C++?

Detailed Solution for Test: Strings - 2 - Question 5

The 'toupper()' function can be used to convert a string to uppercase in C++.

Test: Strings - 2 - Question 6

What is the maximum length of a string that can be stored in C++?

Detailed Solution for Test: Strings - 2 - Question 6

The maximum length of a string that can be stored in C++ depends on the available memory.

Test: Strings - 2 - Question 7

Which of the following is the correct way to compare two strings in C++?

Detailed Solution for Test: Strings - 2 - Question 7

The correct way to compare two strings in C++ is using the '==' operator.

Test: Strings - 2 - Question 8

What is the output of the following code snippet?
string s = "Hello World";
cout << s.substr(6) << endl;

Detailed Solution for Test: Strings - 2 - Question 8

The output of the code snippet is "World" because 's.substr(6)' returns a substring starting from index 6, which is "World" in this case.

Test: Strings - 2 - Question 9

Which of the following functions can be used to convert a string to an integer in C++?

Detailed Solution for Test: Strings - 2 - Question 9

The 'stoi()' function can be used to convert a string to an integer in C++.

Test: Strings - 2 - Question 10

What is the output of the following code snippet?
string s = "Hello World";
s.replace(6, 5, "Everyone");
cout << s << endl;

Detailed Solution for Test: Strings - 2 - Question 10

The output of the code snippet is "Hello Everyone" because 's.replace(6, 5, "Everyone")' replaces a substring starting at index 6 with "Everyone".

Test: Strings - 2 - Question 11

What is the output of the following code snippet?
```cpp
string s = "Hello";
s += " World";
cout << s << endl;
```

Detailed Solution for Test: Strings - 2 - Question 11

The output of the code snippet is "Hello World" because 's += " World"' appends " World" to the existing string.

Test: Strings - 2 - Question 12

What is the output of the following code snippet?
```cpp
string s = "Open";
string t = "AI";
string u = s + t;
cout << u.length() << endl;
```

Detailed Solution for Test: Strings - 2 - Question 12

The output of the code snippet is 9 because 'u.length()' returns the length of the string, which is 9 in this case.

Test: Strings - 2 - Question 13

What is the output of the following code snippet?
```cpp
string s = "OpenAI";
cout << s.at(5) << endl;
```

Detailed Solution for Test: Strings - 2 - Question 13

The output of the code snippet is 'I' because 's.at(5)' returns the character at index 5, which is 'I' in this case.

Test: Strings - 2 - Question 14

What is the output of the following code snippet?
```cpp
string s = "Hello World";
int index = s.find("World");
cout << index << endl;
```

Detailed Solution for Test: Strings - 2 - Question 14

The output of the code snippet is 6 because 's.find("World")' returns the starting index of the first occurrence of "World" in the string, which is 6 in this case.

Test: Strings - 2 - Question 15

What is the output of the following code snippet?
```cpp
string s = "OpenAI";
s[4] = 'B';
cout << s << endl;
```

Detailed Solution for Test: Strings - 2 - Question 15

The output of the code snippet is "OpenBI" because 's[4] = 'B'' replaces the character at index 4 with 'B'.

Test: Strings - 2 - Question 16

What will be the output of the following code?
```cpp
string s = "abcdefgh";
cout << s.substr(1, 3);
```

Detailed Solution for Test: Strings - 2 - Question 16

The output of the code is "bcd" because 's.substr(1, 3)' returns a substring starting at index 1 with a length of 3.

Test: Strings - 2 - Question 17

What will be the output of the following code?
```cpp
string s = "Hello";
cout << s.erase(1, 2);
```

Detailed Solution for Test: Strings - 2 - Question 17

The output of the code is "Hllo" because 's.erase(1, 2)' removes two characters starting from index 1.

Test: Strings - 2 - Question 18

What will be the output of the following code?
```cpp
string s = "apple";
string t = "apple";
if (s == t)
    cout << "Equal";
else
    cout << "Not Equal";
```

Detailed Solution for Test: Strings - 2 - Question 18

The output of the code is "Equal" because 's == t' compares the two strings for equality.

Test: Strings - 2 - Question 19

What will be the output of the following code?
```cpp
string s = "abc";
cout << s.find_first_of("def");
```

Detailed Solution for Test: Strings - 2 - Question 19

The output of the code is -1 because 's.find_first_of("def")' searches for the first occurrence of any character in "def" within the string and returns the index. Since none of those characters are found, it returns -1.

Test: Strings - 2 - Question 20

What will be the output of the following code?
```cpp
string s = "Hello World";
cout << s.replace(6, 5, "Everyone").length();
```

Detailed Solution for Test: Strings - 2 - Question 20

The output of the code is 13 because 's.replace(6, 5, "Everyone").length()' replaces a substring starting at index 6 with "Everyone" and then returns the length of the resulting string.

70 videos|45 docs|15 tests
Information about Test: Strings - 2 Page
In this test you can find the Exam questions for Test: Strings - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Strings - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

70 videos|45 docs|15 tests
Download as PDF

Top Courses for Software Development