Free CPP Exam Braindumps
C++ Certified Professional Programmer Questions 51–55 (page: 12)

Updated On: 9-Feb-2026

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

#include <string>
#include <list>
#include <iostream>
using namespace std;
template<class T> void print(T start, T end) {
while (start != end) {
std::cout << *start << " "; start++;
}
}

int main() {
string t1[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
list<string> l1(t1, t1 + 10);
list<string> l2(l1);
l2.reverse(); l1.splice(l1.end(),l2);
l1.unique();
print(l1.begin(), l1.end()); cout<<endl;
return 0;
}

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

Answer(s): B



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

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

int main () {
int t[] = {1,2,3,4,5,1,2,3,5,4};
vector<int> v (t,t+10);
vector<int>::iterator it;
int m1[] = {1, 3, 2};
it = find_end (v.begin(), v.end(), m1, m1+3);
if (it != v.end())
cout << "Found at position: " << it?v.begin() << endl;
return 0;
}

  1. program outputs: Found at position: 5
  2. program outputs: Found at position: 0
  3. no output
  4. program outputs: Found at position: 10

Answer(s): C



What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?

#include <iostream>
#include <fstream>
#include <string>
#include <list>
#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 () {
ifstream f("test.in");
list<int> l;
for( ; f.good() ; ) {
int i;
f>>i;
l.push_back(i);
}
f.close();
for_each(l.begin(), l.end(), Out<int>(cout));
return 0;
}

Program will output:

  1. 1 2 3
  2. 1 2 3 3
  3. no output
  4. compilation error
  5. program runs forever without output

Answer(s): A



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

#include <vector>
#include <iostream>
int main ()
{
int t[]={1,2,3,4,5};
std::vector<int> v1(t,t+5);
std::vector<int> v2(v1);
v1.resize(10);
v2.reserve(10);
std::vector<int>::iterator i = v1.begin(); int ii = 0;
while (i != v1.end()) { std::cout<<i[ii]<<" ";ii??;i++; }
i = v2.begin();ii=0;
while (i != v2.end()) { std::cout<<i[ii]<<" ";ii??;i++; }
return 0;
}

  1. program outputs 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  2. compilation error
  3. program outputs 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5
  4. program outputs 1 2 3 4 5 0 0 0 0 0 1 2 3 4 5 0 0 0 0 0

Answer(s): A



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

#include <iostream>

using namespace std;

template <class T>
class A {
T _v;
public:
A(T v);
};

template<class T>
A::A(T v):_v(v) {}

int main()
{
A<int> a(2);
cout<<1<<endl;
return 0;
}

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

Answer(s): B



Viewing page 12 of 47
Viewing questions 56 - 60 out of 228 questions


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

AI Tutor AI Tutor 👋 I’m here to help!