String Characters C++ MCQ

Errorlogger
0
1. Which is an instantiation of the basic_string class template?
a) Character
b) String class
c) Memory
d) None of the mentioned


2. Which character is used to terminate the string?
a) $
b) Null
c) Empty
d) None of the mentioned


3. How does the strings are stored in the memory?
a) Contiguous
b) Non-contiguous
c) Null
d) All of the mentioned


4. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str;
  7.         string str2="Steve jobs";
  8.         string str3="He founded apple";
  9.         str.append(str2);
  10.         str.append(str3, 6, 3);
  11.         str.append(str3.begin() + 6, str3.end());
  12.         str.append<int>(5, 0x2E);
  13.         cout << str << '\n';
  14.         return 0;
  15.     }
a) Steve jobs
b) He founded apple
c) Steve
d) None of the mentioned


5. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("Test string");
  7.         for ( string :: iterator it = str.begin(); it != 5; ++it)
  8.             cout << *it;
  9.         return 0;
  10.     }
a) Test
b) string
c) Test string
d) Error


6. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string name ("Jobs");
  7.         string family ("Steve");
  8.         name += " Apple ";
  9.         name += family;
  10.         name += '\n';
  11.         cout << name;
  12.         return 0;
  13.     }
a) Steve Jobs
b) Apple
c) Jobs Apple Steve
d) None of the mentioned


7. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str="Steve Jobs founded the apple";
  7.         string str2 = str.substr (6, 4);
  8.         unsigned pos = str.find("the");
  9.         string str3 = str.substr (pos);
  10.         cout << str2 << ' ' << str3 << '\n';
  11.         return 0;
  12.     }
a) Jobs the apple
b) the apple
c) Steve
d) Jobs


8. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("Steve jobs");
  7.         cout << str.length();
  8.         return 0;
  9.     }
a) 8
b) 10
c) 12
d) 9


9. In which format does the strings are stored?
a) Stack
b) Heap
c) Both a & b
d) None of the mentioned


10. What will happen if a string is empty?
a) It can’t be created
b) Raises an error
c) It can be used
d) None of the mentioned
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !