CPP

CPP

String Class has 8 Questions
How many types of representation are in string?

1
2
3
4
Which is used to return the number of characters in the string?

length
size
both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         char str1[10] = "Hello";
  7.         char str2[10] = "World";
  8.         char str3[10];
  9.         int  len ;
  10.         strcpy( str3, str1);
  11.         strcat( str1, str2)
  12.         len = strlen(str1);
  13.         cout << len << endl;
  14.         return 0;
  15.     }

5
55
11
10
What is the output of this program?
  1.    #include 
  2.    #include 
  3.    using namespace std;
  4.    int main ()
  5.    {
  6.        string str ("nobody does like this");
  7.        string key ("nobody");
  8.        size_t f;
  9.        f = str.rfind(key);
  10.        if (f != string::npos)
  11.            str.replace (f, key.length(), "everybody");
  12.        cout << str << endl;
  13.        return 0;
  14.    }

nobody does like this
nobody
everybody
everybody does like this
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("steve jobs is legend");
  7.         string::iterator it;
  8.         str.erase (str.begin()+ 5, str.end()-7);
  9.         cout << str << endl;      
  10.         return 0;
  11.     }

jobs is
steve legend
steve
none of the mentioned
What is the output of this program?
  1.    #include 
  2.    #include 
  3.    using namespace std;
  4.    int main ()
  5.    {
  6.        string str ("Ubuntu");
  7.        cout << str.capacity();
  8.        cout << str.max_size();
  9.        return 0;
  10.    }

61073741820
51073741820
6 and max size depends on compiler
none of the mentioned
Which method do we use to append more than one character at a time?

append
operator+=
data
both a & b
What is the header file for the string class?

#include
#include
#include
None of the mentioned