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

Updated On: 1-Feb-2026

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

#include <iostream>
using namespace std;

class C {

public:
int _c;
C():_c(0){}
C(int c) { _c = c;}
C operator+=(C & b) {
C tmp;
tmp._c = _c+b._c;
return tmp;
}
};

template <class T>
class A {
T _v;
public:
A() {}
A(T v): _v(v){}
T getV() { return _v; }
void add(T & a) { _v+=a; }
};


int main()
{
A<int> b(2);
A<C> a (5);
C c;
a.add(c);
cout << a.getV() <<endl;
return 0;
}

  1. program will display:2
  2. program will not compile
  3. program will compile
  4. program will cause runtime exception

Answer(s): B



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

#include <vector>
#include <iostream>
int main ()
{
std::vector<int> v1;
for(int i = 0; i<10; i++) { v1.push_back(i); }
v1.resize(4);
std::vector<int>::iterator it = v1.end();
v1.insert(v1.end()?1, 4);
for(int i=0 ; i<= v1.size(); i++) { std::cout<<v1.at(i)+v1[i]<<" "; } std::cout<<std::endl;
return 0;
}

  1. compilation error
  2. program outputs 0 1 2 3 4
  3. program outputs 0 2 4 8 6 and exception
  4. program outputs 0 2 4 6 8
  5. program outputs 0 2 4 8 6

Answer(s): C



Which keywords can be used to define template type parameters? Choose all possible answers:

  1. class
  2. typedef
  3. typename
  4. static
  5. volatile

Answer(s): A,C



What will happen 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<<scientific<<f<<" "<<setprecision(3)<<f<<endl;
return 0;
}

What will be a mantissa part of the numbers displayed:

  1. 1.0126 1.013
  2. 1.012600 10.013
  3. 10.01260 10.013
  4. 1.012600 1.013
  5. 1.0126 1.01

Answer(s): D



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

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool compare(int a, int b) { return a == b; }
int main () {
int t[] = {1,2,3,4,5,1,2,3,4,5};
vector<int> v (t,t+10);
vector<int>::iterator it = v.begin();
int m1[] = {1, 2, 3};

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

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

Answer(s): E



Viewing page 8 of 47
Viewing questions 36 - 40 out of 228 questions



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

Join the CPP Discussion