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

Updated On: 1-Feb-2026

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

#include <iostream>
using namespace std;

int main ()
{
float f1 = 10.0;
float f2 = 10.123;
cout<<noshowpoint<<f1<<" "<<f2;
return 0;
}

Program outputs:

  1. 10 10
  2. 10.0 10.123
  3. compilation error
  4. 10 10.123

Answer(s): D



Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)

#include <iostream>
#include <set>
#include <vector>
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
/* Insert Code Here 1 */

};
/* Insert Code Here 2 */
int main(){
A t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<A> v(t, t+10);
set<A> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(2),s1.upper_bound(7));
for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<i?>getA()<<" ";
}
cout<<endl;
return 0;
}

  1. operator int() const { return a;} inserted at Place 1
  2. bool operator < (const A & b) const { return a<b.a;} inserted at Place 1
  3. bool operator < (const A & b) const { return b.a<a;} inserted at Place 1
  4. bool operator < (const A & a, const A & b) { return a.getA()<b.getA();} inserted at Place 2

Answer(s): A,B,D



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

#include <iostream>
#include <algorithm>
#include <vector>
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);
copy(t, t+10, v1.end());
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}

Program outputs:

  1. 10 5 9 6 2 4 7 8 3 1
  2. 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1
  3. compilation error
  4. runtime exception/segmentation fault

Answer(s): D



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

#include <deque>
#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[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<int> d1(t, t+10);
sort(d1.begin(), d1.end());
deque<int>::iterator it = upper_bound(d1.begin(), d1.end(), 4);
for_each(it, d1.end(), Out<int>(cout));cout<<endl;
return 0;
}

Program outputs:

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

Answer(s): A



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

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class B { int val;
public:
B(int v):val(v){}
int getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} };

template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };

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

Program outputs:

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

Answer(s): D



Viewing page 5 of 47
Viewing questions 21 - 25 out of 228 questions



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

Join the CPP Discussion