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

Updated On: 1-Feb-2026

What happens 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());
s1.insert(v.begin(),v.end());
pair<multiset<int>::iterator,multiset<int>::iterator> range;
range = s1.equal_range(6);
while (range.first != range.second) {
cout<<*range.first<<" "; range.first++;
}
return 0;
}

  1. program outputs: 6 6
  2. program outputs: 5 7
  3. program outputs: 5 5 6 6 7 7
  4. program outputs: 5 5 7 7
  5. program outputs: 1 1 6 6 5 5

Answer(s): A



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

#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.unsetf(ios::hex);
cout<<100<<" ";
return 0;
}

Program outputs:

  1. 64 64
  2. 100 0x64
  3. 0x64 0x64
  4. 64 100
  5. compilation error

Answer(s): D



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;
class A {
int a;
public:
A(int a):a(a) {}
int getA() const { return a;} void setA(int a){ this?>a = a;}
bool operator < ( const A & b) const { return a<b.a;}
};
struct display { void operator() (const A & a) {cout << " " << a.getA();} };
struct add10
{
void operator() (A & a) { a.setA(a.getA()+10) ;}
};

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

  1. program outputs: 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10
  2. program outputs: 20 15 19 16 12 14 17 18 13 11 1 2 3 4 5 6 7 8 9 10
  3. program outputs: 20 15 19 16 12 14 17 18 13 11 11 12 13 14 15 16 17 18 19 20
  4. compilation error

Answer(s): D



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

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class B { int val;
public:
B(int v=0):val(v){}
int getV() const {return val;}
operator int () const { return val;} };
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };
struct Add : public binary_function<B, B, B> {
B operator() (const B & a, const B & b) const {
return a+b; } };
int main() {
B t[]={1,2,3,4,5,6,7,8,9,10};
vector<B> v1(t, t+10);
vector<B> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1));
for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl;
return 0;
}

Program outputs:

  1. 1 2 3 4 5 6 7 8 9 10
  2. 2 3 4 5 6 7 8 9 10 11
  3. 10 9 8 7 6 5 4 3 2 1
  4. 11 10 9 8 7 6 5 4 3 2
  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<<" ";
}
};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() { return start++; }
};
struct Odd { bool operator()(int v) { return v%2==0; }};
int main() {
vector<int> v1(10);
generate(v1.begin(), v1.end(), Sequence(1));
partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out<int>(cout) );cout<<endl;
return 0;
}

Choose all possible outputs:

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

Answer(s): C,D,E



Viewing page 2 of 47
Viewing questions 6 - 10 out of 228 questions



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

Join the CPP Discussion