Explore topic-wise MCQs in C++ Programming.

This section includes 160 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;
void PermutationString( string& orig, string& Permutation )
{
if (orig.empty())
{
cout << Permutation << endl;
return;
}
for (int k = 0; k < orig.size(); ++k)
{
string orig2 = orig;
orig2.erase(k, 1);
string Permutation2 = Permutation;
Permutation2 += orig.at(k);
PermutationString(orig2, Permutation2);
}
}
int main()
{
string orig = "Sumi";
string Permutation;
PermutationString(orig, Permutation);
return 0;
}

A. Sumi
B. imus
C. suim
D. returns all the combination of Sumi
E. None of these
Answer» E. None of these
2.

What is the output of this program?
 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void show(const vector<int>& Data)
{
for (size_t k = 0; k < Data.size(); ++k)
{
cout << Data[i] << ' ';
}
cout << endl;
}
int main()
{
vector<int> Data;
Data.push_back(2);
Data.push_back(6);
Data.push_back(6);
sort(Data.begin(), Data.end());
show(Data);
while(next_permutation(Data.begin(), Data.end()))
show(Data);
return 0;
}

A. 2 6 6
B. 6 2 6
C. 6 6 2
D. All of above
E. None of these
Answer» E. None of these
3.

What is the output of this program?
 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void Result(const vector<int>& VectorData)
{
for (size_t k = 0; k < VectorData.size(); ++k)
{
cout << VectorData[k] << ' ';
}
}
int main()
{
vector<int> VectorData;
VectorData.push_back(4);
VectorData.push_back(8);
sort(VectorData.begin(), VectorData.end());
Result(VectorData);
while(next_permutation(VectorData.begin(), VectorData.end()))
Result(VectorData);
return 0;
}

A. Compilation Error
B. 4 8 8 4
C. 4 8 8
D. 4 8
E. 4
Answer» C. 4 8 8
4.

What is the output of this program?
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
int Numbers[] = {23, 25, 32, 43};
sort (Numbers, Numbers + 4);
do
{
} while ( next_permutation(Numbers, Numbers + 4) );
cout << Numbers[0] << ' ' << Numbers[1] << ' ' << Numbers[2] << ' ' << Numbers[3] << ' n';
return 0;
}

A. Compilation Error
B. 23
C. 23 25
D. 23 25 32
E. 23 25 32 43
Answer» F.
5.

What is the output of this program?
 #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool myfunction (int p,int q)
{
return (p < q);
}
int main ()
{
int var[] = {90, 80, 70, 60, 50};
vector<int> Num(var, var + 5);
partial_sort (Num.begin(), Num.begin() + 4, Num.end());
partial_sort (Num.begin(), Num.begin() + 4, Num.end(),
myfunction);
for (vector<int> :: iterator Iter = Num.begin(); Iter != Num.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 50 60 70 80 90
B. 50 60 70 80
C. 50 60 70
D. 50 60
E. 50
Answer» B. 50 60 70 80
6.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool Function(int k, int L)
{
return (k < L);
}
struct ObjectClass {
bool operator() (int k, int L)
{
return (k < L);
}
} StructObject;
int main ()
{
int arr[] = {112, 125, 101};
vector<int> Number(arr, arr + 3);
sort (Number.begin(), Number.begin() + 2);
sort (Number.begin() + 1, Number.end(), Function);
sort (Number.begin(), Number.end(), StructObject);
for (vector<int> :: iterator Iter = Number.begin(); Iter != Number.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 101 112 125
B. 101 112
C. 101
D. Compilation Error
E. None of these
Answer» B. 101 112
7.

What is the output of this program?
 #include <iostream>
#include <iterator>
#include <list>
using namespace std;
int main ()
{
list<int> DataList;
for (int i = 0; i < 10; i++)
DataList.push_back (i * 30);
list<int> :: iterator firstIter = DataList.begin();
list<int> :: iterator lastIter = DataList.end();
cout << distance(firstIter, lastIter) << endl;
return 0;
}

A. 10
B. 30
C. Compilation Error
D. All of above
E. None of these
Answer» C. Compilation Error
8.

What is the output of this program?
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
int main ()
{
list<int> List1, List2;
for (int k = 0; k <= 3; k++)
{
List1.push_back(k);
List2.push_back(k * 12);
}
list<int> :: iterator Iter;
Iter = List1.begin();
advance (Iter, 3);
copy (List2.begin(), List2.end(), inserter(List1, Iter));
for ( Iter = List1.begin(); Iter != List1.end(); ++Iter )
cout << *Iter << " ";
return 0;
}

A. 0 1 2 0 12
B. Compilation Error
C. 0 1 2 0 12 24 36 3
D. 24 36 3
E. None of these
Answer» D. 24 36 3
9.

What is the output of this program?
#include <iostream>
#include <iterator>
#include <list>
using namespace std;
int main ()
{
list<int> DataList;
for (int k = 0; k < 8; k++)
DataList.push_back (k * 8);
list<int> :: iterator Iter = DataList.begin();
advance (Iter, 6);
cout << *Iter << endl;
return 0;
}

A. Compilation Error
B. 8
C. Runtime Error
D. 48
E. None of these
Answer» E. None of these
10.

What is the output of this program?
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main ()
{
vector<int> VectorData;
for (int k = 0; k <= 8; k++)
VectorData.push_back(k);
VectorData.erase (VectorData.begin() + 6);
VectorData.erase (VectorData.begin(), VectorData.begin() + 4);
for (unsigned k = 0; k < VectorData.size(); ++k)
{
cout << ' ' << VectorData[k];
}
return 0;
}

A. Compilation Error
B. Runtime Error
C. 4 5 7 8
D. 4 5 7
E. None of these
Answer» D. 4 5 7
11.

What is the output of this program?
#include &ltiostream>
#include <set>
using namespace std;
int main()
{
set<int> DataSet;
DataSet.insert(25);
DataSet.insert(20);
DataSet.insert(30);
DataSet.insert(35);
DataSet.insert(18);
set<int> :: const_iterator p;
for(p = DataSet.begin(); p != DataSet.end(); ++p)
cout << *p << ' ';
return 0;
}

A. 18
B. 18 20
C. 18 20 25
D. 18 20 25 30
E. 18 20 25 30 35
Answer» F.
12.

What is the output of this program?
 #include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main ()
{
vector<int> Number;
for (int k = 0; k < 100; k++)
Number.push_back(k);
typedef vector<int> :: iterator iter_int;
reverse_iterator<iter_int> rev_iterator;
rev_iterator = Number.rend() - 6;
cout << *rev_iterator << endl;
return 0;
}

A. 100
B. 6
C. 5
D. Compilation Error
E. None of these
Answer» D. Compilation Error
13.

What is the output of this program?
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main ()
{
vector<int> NewVector;
for (int k = 1; k < 6; ++k)
NewVector.push_back(k * 10);
ostream_iterator<int> out_it (cout,", ");
copy ( NewVector.begin(), NewVector.end(), out_it );
return 0;
}

A. 10,
B. 10, 20,
C. 10, 20, 30,
D. 10, 20, 30, 40,
E. 10, 20, 30, 40, 50,
Answer» F.
14.

What is the output of this program?
#include 
#include
using namespace std;
int main ()
{
try {
double val1, val2;
istream_iterator eos;
istream_iterator iit (cin);
if (iit != eos)
val1 = *iit;
iit++;
if (iit != eos)
val2 = *iit;
cout << (val1 * val2) << endl;
}
catch (...) {
cout << "Unknown exception: " << endl;
}
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage Value
D. It will print the multiplied value of the input
E. Exception
Answer» E. Exception
15.

What is the output of this program?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
try {
map<char, int> Data;
map<char, int> :: iterator Iter;
Data['P'] = 55;
Data['Q'] = 105;
Data['R'] = 155;
Data['S'] = 205;
Iter = Data.find('Q');
Data.erase (Iter);
Data.erase (Data.find('S'));
cout << Data.find('P') -> second << ' n';
}
catch (...)
{
cout << "Unknown exception: " << endl;
}
return 0;
}

A. 205
B. 155
C. 105
D. 55
E. Compilation Error
Answer» E. Compilation Error
16.

What is the output of this program?
#include <vector>
#include <iostream>
#include <typeinfo>
#include <stdexcept>
using namespace std;
int main()
{
vector<int> Data;
Data.push_back(56);
int k = Data[200];
try {
k = Data[0];
cout << k << endl;
}
catch (exception &excep)
{
cout << "Caught: " << excep.what( ) << endl;
cout << "Type: " << typeid( excep ).name( ) << endl;
}
catch (...)
{
cout << "Unknown exception: " << endl;
}
return 0;
}

A. Compilation Error
B. 56
C. 200
D. 100
E. None of these
Answer» C. 200
17.

What is the output of this program?
#include <iostream> 
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int FirstNum[] = {15, 100, 115, 200, 250};
int SecondNum[] = {500, 400, 300, 200, 100};
vector<int> VectorData(100);
vector<int> :: iterator Iter;
sort (FirstNum, FirstNum + 5);
sort (SecondNum, SecondNum + 5);
Iter = set_union (FirstNum, FirstNum + 5, SecondNum, SecondNum + 5, VectorData.begin());
VectorData.resize(Iter-VectorData.begin());
for (Iter = VectorData.begin(); Iter != VectorData.end(); ++Iter)
{
cout << ' ' << *Iter;
}
return 0;
}

A. 15 100
B. 15 100 115 200
C. 15 100 115 200 250 300 400 500
D. 250 300 400 500
E. 250 300
Answer» D. 250 300 400 500
18.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int Numbers[] = {100, 200, 300, 50, 150};
vector<int> Data(Numbers, Numbers + 5);
make_heap (Data.begin(), Data.end());
pop_heap (Data.begin(), Data.end());
Data.pop_back();
cout << Data.front();
return 0;
}

A. 100
B. 200
C. 300
D. 50
E. 150
Answer» C. 300
19.

What is the output of this program?
#include <iostream>
using namespace std;
class vectorClass
{
public:
vectorClass(float float1, float float2)
{
p = float1;
q = float2;
}
vectorClass()
{
}
float p;
float q;
};
vectorClass addvectors(vectorClass vect1, vectorClass vect2);
int main()
{
vectorClass vect1(4, 7);
vectorClass vect2(5, -3);
vectorClass vect3 = addvectors(vect1, vect2);
cout << vect3.p << ", " << vect3.p << endl;
}
vectorClass addvectors(vectorClass vect1, vectorClass vect2)
{
vectorClass result;
result.p = vect1.p + vect2.p;
result.q = vect1.q + vect2.q;
return result;
};

A. 9
B. Compilation Error
C. 9, 9
D. Runtime Error
E. None of these
Answer» D. Runtime Error
20.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector v;
v.push_back(false);
v.flip();
cout << boolalpha;
for (unsigned k = 0; k < v.size(); k++)
cout << v.at(k);
return 0;
}

A. false
B. True
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
21.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool myfunction (int k,int L)
{
return (k }
int main ()
{
int num[] = {10, 11, 15, 13, 25};
vector<int> VectorData (num, num + 5);
partial_sort (VectorData.begin(), VectorData.begin() + 3, VectorData.end());
partial_sort (VectorData.begin(), VectorData.begin() + 2, VectorData.end(),
myfunction);
for (vector<int> :: iterator Iter = VectorData.begin(); Iter != VectorData.end(); ++Iter)
{
cout << ' ' << *Iter;
}
return 0;
}

A. 10
B. 10 11
C. 10 11 13
D. 10 11 13 15
E. 10 11 13 15 25
Answer» F.
22.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int num[] = {3, 5, 7, 9, 11};
vector<int> VectorData(num, num + 6);
make_heap (VectorData.begin(),VectorData.end());
cout << VectorData.front() << ' n';
return 0;
}

A. 11
B. 3
C. 5
D. 7
E. 9
Answer» B. 3
23.

What is the output of this program?
 #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int num[] = {6, 7, 8, 9 ,10};
vector<int> VectorData(num, num + 5);
VectorData.push_back(100);
push_heap (VectorData.begin(),VectorData.end());
cout << VectorData.front() << ' n';
sort_heap (VectorData.begin(),VectorData.end());
return 0;
}

A. 6, 7, 8, 9 ,10
B. 6, 7, 8, 9
C. 100
D. 6, 7, 8
E. 6, 7
Answer» D. 6, 7, 8
24.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int Array[] = {12, 1, 13, 51, 25};
vector<int> VectorData(Array, Array + 5);
make_heap (VectorData.begin(), VectorData.end());
pop_heap (VectorData.begin(), VectorData.end()); VectorData.pop_back();
VectorData.push_back(50); push_heap (VectorData.begin(), VectorData.end());
sort_heap (VectorData.begin(), VectorData.end());
for (unsigned k = 0; k < VectorData.size(); k++)
{
cout << ' ' << VectorData[k];
}
return 0;
}

A. 1 12 13 25 50
B. 1 12 13 25
C. 1 12 13
D. 1 12
E. 1
Answer» B. 1 12 13 25
25.

What is the output of this program?
 #include <iostream>
#include <string>
#include <bitset>
using namespace std;
int main ()
{
string Str;
bitset<5> BitsetData;
BitsetData.set();
Str = BitsetData.to_string<char, char_traits<char>,
allocator<char> >();
cout << Str ;
return 0;
}

A. 1
B. 11
C. 111
D. 1111
E. 11111
Answer» F.
26.

What is the output of this program?
#include <iostream>
#include <set>
using namespace std;
int main ()
{
multiset<int> MultisetData;
for (int k = 0; k < 6; k++) MultisetData.insert(k);
multiset :: key_compare compare = MultisetData.key_comp();
int highest = *MultisetData.rbegin();
multiset :: iterator Iter = MultisetData.begin();
do
{
cout << ' ' << *Iter;
} while (compare(*Iter++, highest));
return 0;
}

A. 0 1 2 3 4 5
B. 0 1 2 3 4
C. 0 1 2 3
D. 0 1 2
E. 0 1
Answer» B. 0 1 2 3 4
27.

What is the output of this program?
#include <iostream>
#include <set>
using namespace std;
int main ()
{
set<int> SetData;
SetData.insert(25);
SetData.insert(15);
SetData.insert(45);
SetData.insert(35);
SetData.insert(55);
while (!SetData.empty())
{
cout << ' ' << *SetData.begin();
SetData.erase(SetData.begin());
}
return 0;
}

A. 15
B. 15 25
C. 15 25 35
D. 15 25 35 45
E. 15 25 35 45 55
Answer» F.
28.

What is the output of this program?

A. Only
B. Spaces
C. InText
D. Only Spaces In Text
E. OnlySpacesInText
Answer» F.
29.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData;
for (int k = 0; k < 5; ++k)
VectorData.push_back(k);
reverse(VectorData.begin(), VectorData.end());
for (vector<int> :: iterator Iter = VectorData.begin(); Iter != VectorData.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 4 3 2 1 0
B. 4 3 2 1
C. 4 3 2
D. 4 3
E. 4
Answer» B. 4 3 2 1
30.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData(5);
fill (VectorData.begin(), VectorData.begin() + 4, 5);
fill (VectorData.begin() + 1, VectorData.end() - 2, 4);
for (vector<int> :: iterator Iter = VectorData.begin(); Iter != VectorData.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 5
B. 5 4
C. 5 4 4 5 0
D. 5 4 4 5
E. 5 4 4
Answer» D. 5 4 4 5
31.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int FirstData[] = {52, 101, 150, 200, 205};
int SecondData[] = {20, 30, 120, 200, 102};
vector<int> v(12);
vector<int> :: iterator Iter;
sort (FirstData, FirstData + 5);
sort (SecondData, SecondData + 5);
Iter = set_union (FirstData, FirstData + 5, SecondData, SecondData + 5, v.begin());
cout << int(Iter - v.begin());
return 0;
}

A. 5
B. 6
C. 7
D. 8
E. 9
Answer» F.
32.

What is the output of this program?
#include <iostream>
#include <list>
using namespace std;
int main ()
{
list<int> ListData;
list<int> :: iterator Iter1, Iter2;
for (int k = 0; k < 12; ++k) ListData.push_back(k * 2);
Iter1 = Iter2 = ListData.begin();
advance (Iter2, 7);
++Iter1;
Iter1 = ListData.erase (Iter1);
Iter2 = ListData.erase (Iter2);
++Iter1;
--Iter2;
ListData.erase (Iter1, Iter2);
for (Iter1 = ListData.begin(); Iter1 != ListData.end(); ++Iter1)
cout << ' ' << *Iter1;
return 0;
}

A. 22
B. 20 22
C. 18 20 22
D. 12 16 18 20 22
E. 0 4 12 16 18 20 22
Answer» F.
33.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData;
VectorData.push_back(45);
VectorData.push_back(55);
VectorData.front() += VectorData.back();
cout << VectorData.front() << ' n';
return 0;
}

A. 55
B. 45
C. 100
D. Compilation Error
E. None of these
Answer» D. Compilation Error
34.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData (5);
for (unsigned k = 0; k < VectorData.size(); k++)
VectorData.at(k) = k;
for (unsigned k = 0; k < VectorData.size(); k++)
cout << ' ' << VectorData.at(k);
return 0;
}

A. 0 1 2 3 4
B. 0 1 2 3
C. 0 1 2
D. 0 1
Answer» B. 0 1 2 3
35.

What is the output of this program?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
deque<int> Data;
int Addition (0);
Data.push_back ( 35 );
Data.push_back ( 56 );
Data.push_back ( 44 );
while (!Data.empty())
{
Addition += Data.back();
Data.pop_back();
}
cout << Addition << ' n';
return 0;
}

A. 35
B. 56
C. 44
D. 135
E. None of these
Answer» E. None of these
36.

What is the output of this program?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int k;
deque<int< Data;
deque<int> :: iterator Iter;
Data.push_back ( 202 );
Data.push_back ( 303 );
Data.push_back ( 404 );
for (Iter = Data.begin(); Iter != Data.end(); ++Iter)
Data.clear();
cout << ' ' << *Iter;
}

A. 202
B. 303
C. 404
D. Segmentation fault
E. None of these
Answer» E. None of these
37.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> num;
for (int k = 1; k < 6; ++k)
num.push_back(k);
rotate(num.begin(), num.begin() + 5, num.end( ));
for (vector<int> :: iterator Iter = num.begin();
Iter != num.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 1
B. 1 2
C. 1 2 3
D. 1 2 3 4
E. 1 2 3 4 5
Answer» F.
38.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool IsOdd (int k)
{
return ((k % 2) == 1);
}
int main ()
{
vector<int> num;
num.push_back(110);
num.push_back(45);
num.push_back(85);
num.push_back(101);
vector<int> :: iterator Iter = find_if (num.begin(),
num.end(), IsOdd);
cout << *Iter << ' n';
return 0;
}

A. 110
B. 85
C. 101
D. 45
E. None of these
Answer» E. None of these
39.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int op_increase (int k)
{
return ++k;
}
int main ()
{
vector<int> p;
vector<int> q;
for (int k = 0; k < 5; k++)
p.push_back (k * 12);
q.resize(p.size());
transform (p.begin(), p.end(), q.begin(), op_increase);
transform (p.begin(), p.end(), q.begin(), p.begin(), plus<int>());
for (vector<int> :: iterator Iter = p.begin(); Iter != p.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 1 25
B. 1 25 49
C. 1 25 49 73
D. 1 25 49 73 97
E. Compilation Error
Answer» E. Compilation Error
40.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int Array[]={ 110, 220, 230, 440, 550 };
vector<int> VectorData (5, 85);
iter_swap(Array, VectorData.begin());
iter_swap(Array + 4,VectorData.begin() + 3);
for (vector<int> :: iterator Iter = VectorData.begin();
Iter != VectorData.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 110 220 230
B. 110 85 85 550 85
C. 110 85 85
D. 85 550 85
E. Compilation Error
Answer» C. 110 85 85
41.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
vector<int> num (6);
fill (num.begin(), num.begin() + 3, 6);
fill (num.begin() + 3,num.end() - 3, 5);
for (vector<int> :: iterator Iter = num.begin();
Iter != num.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 6 6
B. 6 6 6
C. 6 6 6 0 0 0
D. 0 0 0
E. 0 0
Answer» D. 0 0 0
42.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int num[] = { 12, 25, 39 ,42 };
int * ptr;
ptr = find (num, num + 4, 42);
--ptr;
cout << *ptr << ' n';
return 0;
}

A. 12
B. 25
C. 39
D. 42
E. Compilation Error
Answer» D. 42
43.

What is the output of this program?
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
int num[] = { 15, 25, 35, 35, 25, 15, 15, 25};
int* ptrBegin = num;
int* ptrEnd = num + sizeof(num) / sizeof(int);
ptrEnd = remove (ptrBegin, ptrEnd, 25);
for (int* ptr = ptrBegin; ptr != ptrEnd; ++ptr)
cout << ' ' << *ptr;
return 0;
}

A. 35 35
B. 15 35
C. 15 15
D. 15 35 35 15 15
E. Compilation Error
Answer» E. Compilation Error
44.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string Str;
char StrArray[30]= "Hello Interview Mania";
Str = StrArray;
cout << Str << ' n';
return 0;
}

A. Hello
B. Interview
C. Mania
D. Hello Interview Mania
E. Compilation Error
Answer» E. Compilation Error
45.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool IsOdd (int k)
{
return (k % 3) == 1;
}
int main ()
{
vector<int> num;
for (int k = 1; k < 15; ++k) num.push_back(k);
vector<int> :: iterator bound;
bound = partition (num.begin(), num.end(), IsOdd);
for (vector<int> :: iterator Iter = num.begin(); Iter != bound; ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 1
B. 1 13
C. 1 13 10
D. 1 13 10 4
E. 1 13 10 4 7
Answer» F.
46.

What is the output of this program?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
multimap<char, int> MultimapData;
MultimapData.insert(make_pair('P', 150));
MultimapData.insert(make_pair('Q', 250));
MultimapData.insert(make_pair('Q', 300));
MultimapData.insert(make_pair('R', 450));
cout << MultimapData.size() << ' n';
return 0;
}

A. 150
B. 250
C. 300
D. 450
E. 4
Answer» F.
47.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int Array[] = {45, 85, 65, 75, 85, 45, 85, 45, 85, 45};
int countData = count (Array, Array + 10, 45);
cout << countData << " ";
vector<int> num (Array, Array + 10);
countData = count (num.begin(), num.end(), 85);
cout << countData;
return 0;
}

A. 1 1
B. 2 2
C. 3 3
D. 4 4
E. 5 5
Answer» E. 5 5
48.

What is the output of this program?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool myfunction (int k, int L)
{
return (k==L);
}
int main ()
{
int Array[] = {101, 202, 202, 202, 303, 303, 202, 202, 101};
vector<int> num (Array, Array + 9);
vector<int> :: iterator Iter;
Iter = unique (num.begin(), num.end());
num.resize( distance(num.begin(), Iter) );
unique (num.begin(), num.end(), myfunction);
for (Iter = num.begin(); Iter != num.end(); ++Iter)
cout << ' ' << *Iter;
return 0;
}

A. 101 202 303 202 101
B. 101 202 303
C. 101 202 303 202
D. 101 202
E. 101
Answer» B. 101 202 303
49.

What is the output of this program?
#include <iostream> 
#include <algorithm>
using namespace std;
int main ()
{
int Array[] = {101, 201, 301, 301, 201, 101, 101, 201};
int* pbegin = Array;
int* pend = Array + sizeof(Array) / sizeof(int);
pend = remove (pbegin, pend, 201);
for (int* ptr = pbegin; ptr != pend; ++ptr)
cout << ' ' << *ptr;
return 0;
}

A. 101
B. 101 301
C. 101 301 301
D. 101 301 301 101
E. 101 301 301 101 101
Answer» F.
50.

What is the output of this program?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
multimap<char, int> MultimapData;
MultimapData.insert(make_pair('Q', 105));
MultimapData.insert(make_pair('Q', 250));
MultimapData.insert(make_pair('Q', 120));
MultimapData.insert(make_pair('Q', 102));
MultimapData.insert(make_pair('Q', 220));
pair<char, int> highest = *MultimapData.rbegin();
multimap<char, int> :: iterator Iter = MultimapData.begin();
do
{
cout << (*Iter).first << " => " << (*Iter).second << ' n';
} while ( MultimapData.value_comp()(*Iter++, highest) );
return 0;
}

A. 105
B. 250
C. 120
D. 102
E. 220
Answer» B. 250