Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

Which method do we use to append more than one character at a time?


  1.    append
  2.    operator+=
  3.    data
  4.    both a & b
 Discuss Question
Answer: Option D. -> both a & b

None.


Question 2.


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
  1.    61073741820
  2.    51073741820
  3.    6 and max size depends on compiler
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> 6 and max size depends on compiler

In this program, We are printing the capacity and max size of the string.
Output:
$ g++ stri5.cpp
$ a.out
61073741820



Question 3.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
string str ("Microsoft");
7.
for (size_t i = 0; i < str.length();)
8.
{
9.
cout
  1.    M
  2.    Microsoft
  3.    Micro
  4.    runtime error
 Discuss Question
Answer: Option D. -> runtime error

This program will terminate because the cout element is out of range.


Question 4.


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
  1.    jobs is
  2.    steve legend
  3.    steve
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> steve legend

In this program, We are leaving the first 5 characters and last 7 characters and we are erasing 

the remaining the characters.
Output:
$ g++ stri3.cpp
$ a.out
steve legend


Question 5.


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
  1.    nobody does like this
  2.    nobody
  3.    everybody
  4.    everybody does like this
 Discuss Question
Answer: Option D. -> everybody does like this

rfind is used to find the characters in the string and replace is used to replace with certain characters.
Output:
$ g++ stri2.cpp
$ a.out
everbody does like this


Question 6.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
string str ("microsoft");
7.
string::reverse_iterator r;
8.
for (r = str.rbegin() ; r < str.rend(); r++ )
9.
cout
  1.    microsoft
  2.    micro
  3.    tfosorcim
  4.    tfos
 Discuss Question
Answer: Option C. -> tfosorcim

'rbegin' is used to reverse the given the string.
Output:
$ g++ stri1.cpp
$ a.out
tfosorcim


Question 7.


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
  1.    5
  2.    55
  3.    11
  4.    10
 Discuss Question
Answer: Option D. -> 10

In the program, We are concatanating the str1 and str2 and printing
it’s total length. So the length is 10.
Output:
$ g++ stri.cpp
$ a.out
10


Question 8.

Which is used to return the number of characters in the string?


  1.    length
  2.    size
  3.    both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

Both will return the number of characters that conform the string's content.



Question 9.


What is the header file for the string class?


a) #include
b) #include
c) #include
d) None of the mentioned
  1.    length
  2.    size
  3.    both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> both a & b

Answer : c 
Explanation:None.



Question 10.

How many types of representation are in string?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option B. -> 2

C++ provides following two types of string representations. They are C-style character string and 

string class type with Standard C++.


Latest Videos

Latest Test Papers