Class 7  >  C++ Programming for Beginners  >  Test: C++ Strings Download as PDF

Test: C++ Strings


Test Description

15 Questions MCQ Test C++ Programming for Beginners | Test: C++ Strings

Test: C++ Strings for Class 7 2023 is part of C++ Programming for Beginners preparation. The Test: C++ Strings questions and answers have been prepared according to the Class 7 exam syllabus.The Test: C++ Strings MCQs are made for Class 7 2023 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: C++ Strings below.
Solutions of Test: C++ Strings questions in English are available as part of our C++ Programming for Beginners for Class 7 & Test: C++ Strings solutions in Hindi for C++ Programming for Beginners course. Download more important topics, notes, lectures and mock test series for Class 7 Exam by signing up for free. Attempt Test: C++ Strings | 15 questions in 15 minutes | Mock test for Class 7 preparation | Free important questions MCQ to study C++ Programming for Beginners for Class 7 Exam | Download free PDF with solutions
1 Crore+ students have signed up on EduRev. Have you?
Test: C++ Strings - Question 1

Which character is used to terminate the string?

Detailed Solution for Test: C++ Strings - Question 1

A string of characters is stored in successive elements of a character array are terminated by the NULL character.

Test: C++ Strings - Question 2

How many maximum number of parameters does a string constructor can take?

Detailed Solution for Test: C++ Strings - Question 2

string(other_string, position, count). It is a type of constructor for the string.

Test: C++ Strings - Question 3

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str;
        string str2="Steve jobs";
        string str3="He founded apple";
        str.append(str2);
        str.append(str3, 6, 3);
        str.append(str3.begin() + 6, str3.end());
        str.append(5,0x2e);
        cout << str << '\n';
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 3

In this program, We are adding characters to the string, So the output will as follows after addition of characters.
Output:

$ g++ str.cpp
$ a.out
Steve jobsndended apple.....

Test: C++ Strings - Question 4

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("I like to code in C");
        unsigned sz = str.size();
        str.resize (sz + 2, '+');
        str.resize (14);
        cout << str << '\n';
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 4

In this program, We are resizing the string by adding + and then we are resizing it to 14.
Output:
$ g++ basicst.cpp
$ a.out
I like to code

Test: C++ Strings - Question 5

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string name ("Jobs");
        string family ("Steve");
        name += " Apple ";
        name += family;
        name += '\n';
        cout << name;
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 5

In this program, We are adding the characters at the end of the current value.
Output:
$ g++ str1.cpp
$ a.out
Jobs Apple Steve

Test: C++ Strings - Question 6

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Steve jobs founded the apple");
        string str2 ("apple");
        unsigned found = str.find(str2);
        if (found != string :: npos)
            cout << found << '\n';
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 6

In this program, We are finding a string by using the find method.

$ g++ basicst2.cpp
$ a.out
23

Test: C++ Strings - Question 7

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Steve jobs");
        cout << str.length();
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 7

In this program, We are finding the length of the string.
Output:
$ g++ str3.cpp
$ a.out
10

Test: C++ Strings - Question 8

What will be the output of the following C++ code?

    #include <iostream>  
    #include <cstring>
    #include <string>
    using namespace std;
    int main () 
    {
        string str ("Steve jobs");
        char * cstr = new char [str.length() + 1];
        strcpy (cstr, str.c_str());
        char * p = strtok (cstr," ");
        while (p != 0)
        {
            cout << p << '\n';
            p = strtok(NULL," ");
        }
        delete[] cstr;
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 8

In this program, We are breaking up the strings into the form of tokens.
Output:
$ g++ basicst4.cpp
$ a.out
Steve 
jobs

Test: C++ Strings - Question 9

What will happen if a string is empty?

Detailed Solution for Test: C++ Strings - Question 9

An empty string is a character array with the NULL character in the zeroth index position.

Test: C++ Strings - Question 10

How many parameters can a resize method take?

Detailed Solution for Test: C++ Strings - Question 10

There can be one or two parameters in resize method. They are string length and an optional new character to be inserted.

Test: C++ Strings - Question 11

Which is an instantiation of the basic_string class template?

Detailed Solution for Test: C++ Strings - Question 11

The string class is an instantiation of the basic_string class template.

Test: C++ Strings - Question 12

Which header file is used to manipulate the string?

Detailed Solution for Test: C++ Strings - Question 12

To use the string class, We have to use #include<string> header file.

Test: C++ Strings - Question 13

How does the strings are stored in the memory?

Detailed Solution for Test: C++ Strings - Question 13

The characters of a string are stored contiguously in the memory.

Test: C++ Strings - Question 14

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Test string");
        for ( string :: iterator it = str.begin(); it != 5; ++it)
            cout << *it;
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 14

In the for loop, We are not allowed to give a numeric value in string, So it is arising an error.

Test: C++ Strings - Question 15

What will be the output of the following C++ code?

    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("Steve jobs");
        cout << str.capacity() << "\n";
        return 0;
    }

Detailed Solution for Test: C++ Strings - Question 15

str.capacity() returns the size of the storage space currently allocated for the string, expressed in terms of bytes and capacity of the string may be equal or greater. So the answer is not fix, depends on the compiler.
Output:
$ g++ basicst1.cpp
$ a.out
10

15 videos|20 docs|13 tests
Use Code STAYHOME200 and get INR 200 additional OFF
Use Coupon Code
Information about Test: C++ Strings Page
In this test you can find the Exam questions for Test: C++ Strings solved & explained in the simplest way possible. Besides giving Questions and answers for Test: C++ Strings, EduRev gives you an ample number of Online tests for practice