C++ Institute CPP Exam
C++ Certified Professional Programmer (Page 4 )

Updated On: 1-Feb-2026

What happens when you attempt to compile and run the following code?

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
int second[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
map<int,string> m;
for(int i=0; i<10; i++) {
m.insert(pair<int,string>(second[i],first[i]));
}
if (m[11] == "eleven") {
cout<<"eleven ";
}
for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {
cout<<i?>second<<" ";
}
cout<<m.size();
return 0;
}

  1. program outputs: one two three four five six seven eight nine ten 11
  2. program outputs: one two three four five six seven eight nine ten 10
  3. program outputs: one two three four five six seven eight nine ten 10
  4. program outputs: eleven one two three four five six seven eight nine ten 10
  5. runtime exception

Answer(s): A



What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t+10);
multiset<int> s1(v.begin(),v.end());
multiset<int, greater<int> > s2(v.begin(), v.end());
for(multiset<int, greater<int> >::iterator i=s2.begin();i!= s2.end(); i++) {
cout<<*i<<" ";
}
for(multiset<int>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<*i<<" ";
}
cout<<endl;
return 0;
}

The output will be:

  1. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
  2. 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  3. 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
  4. 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9

Answer(s): D



What happens when you attempt to compile and run the following code?

#include <list>
#include <deque>
#include <iostream>
using namespace std;
template<class T>
void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}
int main()
{
int t1[] = { 1, 7, 8, 4, 5 };
list<int> l1(t1, t1 + 5);
int t2[] = { 3, 2, 6, 9, 0 };
deque<int> d1(t2, t2 + 5);
l1.sort();
d1.sort();
l1.merge(d1);
print(l1.begin(), l1.end());
print(d1.begin(), d2.end()); cout<<endl;
return 0;
}

  1. program outputs: 0 1 2 3 4 5 6 7 8 9 0 2 3 6 9
  2. program outputs: 0 1 2 3 4 5 6 7 8 9
  3. program outputs: 9 8 7 6 5 4 3 2 1 0
  4. compilation error

Answer(s): D



What happens when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
int t[] = {1,2,3,3,5,1,2,4,4,5};
vector<int> v (t,t+10);
vector<int>::iterator it = v.begin();

while ( (it = adjacent_find (it, v.end())) != v.end()) {
cout<<it?v.begin()<<" ";it++;
}
cout<< endl;
return 0;
}

  1. program outputs: 2 3
  2. program outputs: 2 7
  3. program outputs: 3 8
  4. compilation error
  5. program will run forever

Answer(s): B



What happens when you attempt to compile and run the following code?

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
float f = 10.126;
cout.unsetf(ios::floatfield);
cout<<showpoint<<f<<fixed<<" "<<setprecision(2)<<f<<endl;
return 0;
}

Program outputs:

  1. 10.126 10
  2. 10.126 10.12
  3. 10.1260 10.13
  4. 10.126 10.13

Answer(s): C



Viewing page 4 of 47
Viewing questions 16 - 20 out of 228 questions



Post your Comments and Discuss C++ Institute CPP exam prep with other Community members:

Join the CPP Discussion