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

Updated On: 24-Feb-2026

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

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };

int main() {
int t[]={3,2,4,1,5,10,9,7,8,6};
vector<int> v1(t,t+10);
cout<<*max_element(v1.begin(), v1.end());
return 0;
}

Program outputs:

  1. 3
  2. 1
  3. 6
  4. 10
  5. compilation error

Answer(s): D



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

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };

int main() {
int t1[]={3,2,4,1,5};
int t2[]={5,6,8,2,1};
vector<int> v1(10);
sort(t1, t1+5);
sort(t2, t2+5);
set_intersection(t1,t1+5,t2,t2+5,v1.begin());
for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;
return 0;
}

Program outputs:

  1. compilation error
  2. 1 2 3 4 5 6 8 0 0 0
  3. 1 2 3 4 5 6 8 2 1 0
  4. 1 1 2 2 3 4 5 5 6 8
  5. 1 2 5 0 0 0 0 0 0 0

Answer(s): E



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

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

void myfunction(int i) {
cout << " " << i;
}

int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector<int> v1(t, t + 10);
deque<int> d1(t, t + 10);
set<int> s1(t, t + 10);

for_each(v1.begin(), v1.end(), myfunction); // Line I

for_each(d1.begin(), d1.end(), myfunction); // Line II

for_each(s1.begin(), s1.end(), myfunction); // Line III
return 0;
}

  1. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10
  2. program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
  3. program outputs: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  4. compilation error in line I
  5. compilation error in line III

Answer(s): A



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

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

int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map<int, int> m;
for(int i=0; i < 10; i++) {
m[i]=t[i];
}
pair<const int,int> p(5,5);
map<int, int>::iterator it = find(m.begin(), m.end(), p);
if (it != m.end())
{
cout<<it?>first<<endl;
}
else
{
cout<<"Not found!\n";
}
return 0;
}

Program outputs:

  1. 5
  2. Not found!
  3. 10
  4. compilation error

Answer(s): B



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

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

void myfunction(int i) {
cout << " " << i;
}

int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
set<int> s1(t, t+10);
vector<int> v1(s1.rbegin(), s1.rend());
swap_ranges(s1.begin(), s1.end(), v1.begin());
for_each(v1.begin(), v1.end(), myfunction);
for_each(s1.begin(), s1.end(), myfunction);
return 0;
}

Program outputs:

  1. 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
  2. compilation error
  3. 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  4. 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
  5. 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1

Answer(s): B






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

Join the CPP Discussion