Software Development Exam  >  Software Development Tests  >  Basics of C++  >  Test: Strings - 1 - Software Development MCQ Download as PDF

Test: Strings - 1 - Software Development MCQ


Test Description

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

Test: Strings - 1 for Software Development 2024 is part of Basics of C++ preparation. The Test: Strings - 1 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Strings - 1 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Strings - 1 below.
Solutions of Test: Strings - 1 questions in English are available as part of our Basics of C++ for Software Development & Test: Strings - 1 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 - 1 | 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
1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Strings - 1 - Question 1

Which header file should be included to work with strings in C++?

Detailed Solution for Test: Strings - 1 - Question 1

The string header file (string.h) should be included to work with strings in C++.

Test: Strings - 1 - Question 2

What is the maximum number of characters that can be stored in a string object in C++?

Detailed Solution for Test: Strings - 1 - Question 2

In C++, there is no specific limit on the number of characters that can be stored in a string object.

Test: Strings - 1 - Question 3

What is the purpose of the 'getline()' function in C++?

Detailed Solution for Test: Strings - 1 - Question 3

The 'getline()' function is used to read a line of text from the console.

Test: Strings - 1 - Question 4

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

Detailed Solution for Test: Strings - 1 - Question 4

All of the options are valid ways to concatenate two strings in C++.

Test: Strings - 1 - Question 5

Which function is used to find the length of a string in C++?

Detailed Solution for Test: Strings - 1 - Question 5

All of the options (length(), size(), and strlen()) can be used to find the length of a string in C++.

Test: Strings - 1 - Question 6

What does the 'c_str()' function do in C++?

Detailed Solution for Test: Strings - 1 - Question 6

The c_str() function is used to convert a string to a character array (C-style string).

Test: Strings - 1 - Question 7

What is the output of the following code snippet?
string str = "Hello";
cout << str[2];

Detailed Solution for Test: Strings - 1 - Question 7

The output will be 'l' because string indexing starts from 0, so str[2] refers to the third character in the string.

Test: Strings - 1 - Question 8

Which function is used to extract a substring from a string in C++?

Detailed Solution for Test: Strings - 1 - Question 8

The substr() function is used to extract a substring from a string in C++.

Test: Strings - 1 - Question 9

What is the return type of the 'find()' function in C++?

Detailed Solution for Test: Strings - 1 - Question 9

The find() function returns a value of type size_t, which is an unsigned integer type.

Test: Strings - 1 - Question 10

Which of the following is not a valid way to compare two strings in C++?

Detailed Solution for Test: Strings - 1 - Question 10

The equals() function is not a valid way to compare two strings in C++.

Test: Strings - 1 - Question 11

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

Detailed Solution for Test: Strings - 1 - Question 11

The output will be "Hello World" because the + operator can be used to concatenate strings.

Test: Strings - 1 - Question 12

What is the output of the following code snippet?
```cpp
string str = "OpenAI";
cout << str.substr(2, 3);
```

Detailed Solution for Test: Strings - 1 - Question 12

The output will be "pen" because substr(2, 3) extracts a substring starting from index 2 with a length of 3.

Test: Strings - 1 - Question 13

What is the output of the following code snippet?

```cpp
string str = "Hello";
str[1] = 'X';
cout << str;
```

Detailed Solution for Test: Strings - 1 - Question 13

The output will be "HXllo" because str[1] is replaced with 'X'.

Test: Strings - 1 - Question 14

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

Detailed Solution for Test: Strings - 1 - Question 14

The output will be 6 because the find() function returns the position of the substring "World" within the string.

Test: Strings - 1 - Question 15

What is the output of the following code snippet?
```cpp
string str = "Programming";
cout << str.size() << " " << str.length();
```

Detailed Solution for Test: Strings - 1 - Question 15

The output will be "11 11" because size() and length() both return the length of the string.

Test: Strings - 1 - Question 16

What is the output of the following code snippet?
```cpp
string str = "Hello World";
reverse(str.begin(), str.end());
cout << str;
```

Detailed Solution for Test: Strings - 1 - Question 16

The output will be "dlroW olleH" because the reverse() function is used to reverse the string.

Test: Strings - 1 - Question 17

What is the output of the following code snippet?
```cpp
string str1 = "Hello";
string str2 = "Hello";
if (str1.compare(str2) == 0)
    cout << "Equal";
else
    cout << "Not equal";
```

Detailed Solution for Test: Strings - 1 - Question 17

The output will be "Equal" because the compare() function returns 0 when the strings are equal.

Test: Strings - 1 - Question 18

What is the output of the following code snippet?
```cpp
string str = "Hello World";
str.erase(5, 5);
cout << str;
```

Detailed Solution for Test: Strings - 1 - Question 18

The output will be "Hello" because erase(5, 5) removes 5 characters starting from index 5.

Test: Strings - 1 - Question 19

What is the output of the following code snippet?
```cpp
string str = "Hello World";
str.insert(6, "C++ ");
cout << str;
```

Detailed Solution for Test: Strings - 1 - Question 19

The output will be "Hello C++ World" because insert(6, "C++ ") inserts the string "C++ " at index 6.

Test: Strings - 1 - Question 20

What is the output of the following code snippet?
```cpp
string str = "Hello World";
str.replace(6, 5, "C++");
cout << str;
```

Detailed Solution for Test: Strings - 1 - Question 20

The output will be "Hello C++ld" because replace(6, 5, "C++") replaces 5 characters starting from index 6 with the string "C++".

70 videos|44 docs|15 tests
Information about Test: Strings - 1 Page
In this test you can find the Exam questions for Test: Strings - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Strings - 1, EduRev gives you an ample number of Online tests for practice
70 videos|44 docs|15 tests
Download as PDF
Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!