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

Updated On: 1-Feb-2026

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

#include <deque>
#include <vector>
#include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector<int> v1(t, t+5);
deque<int> d1;
d1.assign(v1.end(), v1.begin());
for(int i=0; i<d1.size(); i++)
{
cout<<d1.at(i)<<" ";
}
cout<<endl;
return 0;
}

  1. program outputs 5 4 3 2 1
  2. program outputs 1 2 3 4 5
  3. compilation error in line 8
  4. compilation error in line 10
  5. segmentation fault runtime exception

Answer(s): E



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.33<<" ";
cout.setf(ios::showbase);
cout<<100.33<<" ";
return 0;
}

Program outputs:

  1. 64.21 64.21
  2. 64.21 0x64.21
  3. 0x64.21 0x64.21
  4. 100.33 100.33
  5. compilation error

Answer(s): D



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

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

class A
{
int a;
public:
A(int a) {this?>a = a; c++;}
~A() { c??;}
static int c;
};
int A::c(0);
int main ()
{
A t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 , 9};
vector<A> v1(t, t+10);
deque<A> d1(v1.begin(), v1.end());
deque<A> d2;
d2 = d1;
cout<<A::c<< endl;
return 0;
}

How many objects of type A will be created:

  1. 10
  2. 20
  3. 30
  4. 40

Answer(s): D



What will happen when you attempt to compile and run the following code? Choose all possible answers.

#include <iostream>

using namespace std;

class B {};

template <typename 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> a(1);
A<B> b;
a.add(10);
cout << a.getV() <<endl;
return 0;
}

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

Answer(s): A,C



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

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

void print(int v) {
cout<<v<<" ";
}
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() {
return start++;
}
};
int main() {
vector<int> v1(10);
generate_n(v1.begin(), 10, Sequence(1));
for_each(v1.begin(), v1.end(), print);
cout<<endl;
return 0;
}

Program outputs:

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

Answer(s): A



Viewing page 7 of 47
Viewing questions 31 - 35 out of 228 questions



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

Join the CPP Discussion