Explore topic-wise MCQs in C++ Programming.

This section includes 26 Mcqs, each offering curated multiple-choice questions to sharpen your C++ Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("InterviewMania");
string::reverse_iterator Rev;
for (Rev = s.rbegin(); Rev < s.rend(); Rev++ )
cout << *Rev;
return 0;
}

A. InterviewMania
B. 14
C. ainaMweivretnI
D. Compilation Error
E. None of these
Answer» D. Compilation Error
2.

What is the output of this program?
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char s1[10] = "Interview";
char s2[10] = "Mania";
char s3[10];
int length ;
strcpy( s3, s1);
strcat( s1, s2);
length = strlen(s1);
cout << length << endl;
return 0;
}

A. Interview
B. Mania
C. Interview Mania
D. 14
E. None of these
Answer» E. None of these
3.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Interview Mania");
cout << s.capacity();
cout << s.max_size();
return 0;
}

A. Interview Mania
B. 159223372036854775807
C. Compilation Error
D. 6 and max size depends on compiler
E. None of these
Answer» E. None of these
4.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Interview Mania");
for (size_t k = 0; k < s.length();)
{
cout << s.at(k-1);
}
return 0;
}

A. Interview
B. Mania
C. Interview Mania
D. Compilation Error
E. Runtime Error
Answer» F.
5.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Interview Mania is being legend");
string::iterator itr;
s.erase (s.begin()+ 15, s.end()-7);
cout << s << endl;
return 0;
}

A. Interview Mania is being legend
B. Interview Mania legend
C. Interview Mania
D. All of above
E. None of these
Answer» C. Interview Mania
6.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s="Manjesh Ojha founded the Interview Mania";
string s2 = s.substr (0, 12);
unsigned pos = s.find("the");
string s3 = s.substr (pos);
cout << s2 << ' ' << s3 << ' n';
return 0;
}

A. Manjesh Ojha founded the Interview Mania
B. Manjesh Ojha
C. Interview Mania
D. founded
E. Manjesh Ojha the Interview Mania
Answer» F.
7.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string name ("Manjesh");
string family ("Ojha");
name += " Interview Mania ";
name += family;
name += ' n';
cout << name;
return 0;
}

A. Manjesh
B. Ojha
C. Interview Mania
D. Manjesh Ojha Interview Mania
E. Manjesh Interview Mania Ojha
Answer» F.
8.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Testing str...");
for ( string :: iterator Iter = str.begin(); Iter != 5; ++Iter)
cout << *Iter;
return 0;
}

A. Compilation Error
B. Testing str...
C. Runtime Error
D. Garbage value
E. None of these
Answer» B. Testing str...
9.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s1;
string s2="Manjesh Ojha";
string s3="He founded Interview Mania";
s1.append(s2);
s1.append(s3, 2, 4);
s1.append(s3.begin() + 6, s3.end());
s1.append(5, 0x2E);
cout << s1 << ' n';
return 0;
}

A. Manjesh Ojha
B. He founded Interview Mania
C. Manjesh Ojha founded Interview Mania.....
D. Compilation Error
E. None of these
Answer» D. Compilation Error
10.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Prayagraj Shakya");
cout << str.capacity() << " n";
return 0;
}

A. Runtime Error
B. 16
C. Prayagraj Shakya
D. Compilation Error
E. None of these
Answer» C. Prayagraj Shakya
11.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Coding is my life");
unsigned sz = s.size();
s.resize (sz + 2, '+');
s.resize (13);
cout << s << ' n';
return 0;
}

A. my life
B. Coding is my life
C. Coding is my
D. Compilation Error
E. None of these
Answer» D. Compilation Error
12.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Nobody does like Interview Mania.");
string key ("Nobody");
size_t f;
f = s.rfind(key);
if (f != string::npos)
s.replace (f, key.length(), "Everybody");
cout << s << endl;
return 0;
}

A. Nobody
B. Everybody
C. Everybody does like Interview Mania.
D. Nobody does like Interview Mania.
E. None of these
Answer» D. Nobody does like Interview Mania.
13.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Bjarne Stroustrup founded the C++");
string s2 ("C++");
unsigned found = s.find(s2);
if (found != string :: npos)
cout << found << ' n';
return 0;
}

A. founded the C++
B. Bjarne Stroustrup
C. C++
D. 30
E. None of these
Answer» E. None of these
14.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s ("Ajit Kumar");
unsigned found = s.find_first_of("Gupta");
while (found != string :: npos)
{
s[found] = '*';
found = s.find_first_of("Gupta", found + 1);
}
cout << s << ' n';
return 0;
}

A. Ajit Kumar
B. Gupta
C. Compilation Error
D. Runtime Error
E. Segmentation fault
Answer» F.
15.

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

A. width
B. length
C. size
D. both size & length
E. None of these
Answer» E. None of these
16.

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

A. append
B. operator+=
C. both append & operator+=
D. data
E. None of these
Answer» E. None of these
17.

What is the header file for the string class?

A. #include<str>
B. #include<string>
C. #include<ios>
D. All of avove
E. None of these
Answer» C. #include<ios>
18.

How many types of representation are in the string?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» D. 1
19.

What will happen if a string is empty?

A. It can be used
B. It can t be created
C. Raises an error
D. All of above
E. None of these
Answer» B. It can t be created
20.

Where are the strings stored?

A. Int
B. Stack
C. Heap
D. Both Stack & Heap
E. None of these
Answer» E. None of these
21.

How does the strings are stored in the memory?

A. Null
B. Contiguous
C. Non-contiguous
D. All of above
E. None of these
Answer» C. Non-contiguous
22.

Which character is used to terminate the string?

A. Empty
B. $
C. Null
D. All of above
E. None of these
Answer» D. All of above
23.

Which is an instantiation of the basic_string class template?

A. String class
B. Memory
C. Character
D. All of above
E. None of these
Answer» B. Memory
24.

Which header file is used to manipulate the string?

A. container
B. iostream
C. iomanip
D. string
E. None of these
Answer» E. None of these
25.

How many parameters can a resize method take?

A. 1
B. 2
C. 3
D. 1 or 2
E. None of these
Answer» E. None of these
26.

What is the difference between unsigned int length() and unsigned int size()?

A. They are same
B. Returns a different value but they are same
C. Returns a different value
D. All of above
E. None of these
Answer» B. Returns a different value but they are same