Weekend Sale - Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmaspas7

Easiest Solution 2 Pass Your Certification Exams

CPP C++ Institute C++ Certified Professional Programmer Free Practice Exam Questions (2025 Updated)

Prepare effectively for your C++ Institute CPP C++ Certified Professional Programmer certification with our extensive collection of free, high-quality practice questions. Each question is designed to mirror the actual exam format and objectives, complete with comprehensive answers and detailed explanations. Our materials are regularly updated for 2025, ensuring you have the most current resources to build confidence and succeed on your first attempt.

Page: 3 / 4
Total 228 questions

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

#include

#include

using namespace std;

template

void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

int main()

{

int t1[] ={ 1, 7, 8, 4, 5 };

list l1(t1, t1 + 5);

int t2[] ={ 3, 2, 6, 9, 0 };

list l2(t2, t2 + 5);

l1.sort();

list::iterator it = l2.begin();

it++; it++;

l1.splice(l1.end(),l2, it, l2.end());

print(l1.begin(), l1.end()); cout<<"Size:"<

print(l2.begin(), l2.end()); cout<<"Size:"<

return 0;

}

A.

program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 Size:2

B.

program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 6 9 0 Size:5

C.

compilation error

D.

program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 Size:2

E.

program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 6 9 0 Size:5

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={3,2,4,1,5,6,10,8,7,9};

vector v1(t, t+10);

for_each(v1.begin(), v1.end(), bind2nd(plus(), 1));

for_each(v1.rbegin(), v1.rend(), Out(cout));cout<

return 0;

}

Program outputs:

A.

3 2 4 1 5 6 10 8 7 9

B.

4 3 5 2 6 7 11 9 8 10

C.

9 7 8 10 6 5 1 4 2 3

D.

10 8 9 11 7 6 2 5 3 4

E.

compilation error

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3?

#include

#include

using namespace std;

int main ()

{

int a,b,c;

cin>>a>>b>>c;

cout<

return 0;

}

Program will output:

A.

123

B.

1 2 3

C.

1.12.23.3

D.

1.1 2.2 3.3

E.

none of these

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end?

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) {out<

int main ()

{

list l;

for( ; !cin.bad() ; )

{

int i;

cin>>i;

l.push_back(i);

}

for_each(l.begin(), l.end(), Out(cout));

return 0;

}

Program will output:

A.

1 2 3

B.

1 2 3 end

C.

1

D.

compilation error

E.

program runs forever without output

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

#include

#include

#include

#include

using namespace std;

bool identical(int a, int b) {

return b == 2*a?true:false;

}

int main() {

int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};

int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};

vector v1(t, t + 15);

deque d1(u, u + 15);

pair::iterator, vector::iterator > result;

result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I

if (result.first == d1.end() && result.second == v1.end()) {//Line II

cout<<"Identical\n";

} else {

cout<<"Not identical\n";

}

return 0;

}

Program outputs:

A.

Identical

B.

Not identical

C.

compilation error at line marked I

D.

compilation error at line marked II

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

#include

#include

#include

#include

#include

using namespace std;

struct display {

void operator() (int i) {cout << " " << i;}

};

int main() {

int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), display); //Line I

for_each(d1.begin(), d1.end(), *(new display())); // Line II

for_each(s1.begin(), s1.end(), display()); // Line III

return 0;

}

A.

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

B.

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

C.

compilation error in line I

D.

compilation error in line II

E.

compilation error in line III

Which stack initialization (line numbers) are correct? Choose all that apply.

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;

list mylist;

vector myvector;

stack first;// Line I

stack second(mydeck);// Line II

stack third(second);// Line III

stack > fourth(mylist);// Line IV

stack > fifth(myvector);// Line V

return 0;

}

A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t1[]={3,2,4,1,5};

int t2[]={6,10,8,7,9};

vector v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

merge(t1,t1+5,t2,t2+5,v1.begin());

for_each(v1.begin(), v1.end(), Out(cout));cout<

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 10 8 7 9

B.

3 2 4 1 5 6 7 8 9 10

C.

3 2 4 1 5 6 10 8 7 9

D.

1 2 3 4 5 6 7 8 9 10

E.

compilation error

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

#include

#include

#include

#include

using namespace std;

template

void print(T start, T end)

{

while (start != end)

cout<<*start++;

}

int main ()

{

string t[] = {"one", "two" ,"three" ,"four", "five"};

vectorv1(t, t+5);

dequed1(v1.rbegin(), v1.rend());

d1.push_back("zero");

print(d1[0].rbegin(),d1[0].rend());

return 0;

}

A.

program outputs: orez

B.

program outputs: evif

C.

compilation error

D.

program outputs: five

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

#include

#include

#include

using namespace std;

int main () {

int t[] = {1,2,3,4,5,1,2,3,4,5};

vector v (t,t+10);

vector::iterator it;

int m1[] = {1, 2, 3};

it = search (v.begin(), v.end(), m1, m1+3);

cout << "found at position: " << it?v.begin() << endl;

return 0;

}

Program outputs:

A.

found at position: 5

B.

found at position: 0

C.

found at position: 6

D.

found at position: 1

E.

found at position: 10

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={3,2,4,1,5,10,9,7,8,6};

vector v1(t,t+10);

cout<<*max_element(v1.begin(), v1.end());

return 0;

}

Program outputs:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

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

#include

#include

#include

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;} };

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

B t[]={3,2,4,1,5,10,9,7,8,6};

vector v1(t,t+10);

sort(v1.begin(), v1.end(), greater());

cout<<*min_element(v1.begin(), v1.end());

return 0;

}

Program outputs:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

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

#include

#include

#include

#include

#include

using namespace std;

int main()

{

int t[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

deque mydeck(t, t+10);list mylist(t,t+10);

queue first;

queue second(mydeck);

queue third(second);

queue > fourth(mylist);

mylist.clear();third.clear();

cout<

cout<

return 0;

}

A.

program outputs: 10 0

10 0

B.

program outputs: 0 0

0 0

C.

program outputs: 10 10

10 10

D.

program outputs: 10 0

0 10

E.

compilation error

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={3,2,4,1,5,10,9,7,8,6};

vector v1(t,t+10);

sort(v1.begin(), v1.end(), greater());

cout<

return 0;

}

Program outputs:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

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

#include

#include

#include

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

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

sort(d1.begin(), d1.end());

deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4));

for_each(it, d1.end(), Out(cout)); cout<

return 0;

}

Program outputs:

A.

5 6 7 8 9 10

B.

4 5 6 7 8 9 10

C.

6 7 8 9 10

D.

1 2 3 4 5

E.

1 2 3 4

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

#include

#include

#include

using namespace std;

template void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

class A {

int a;

public:

A(int a):a(a){}

operator int () const { return a;}int getA() const { return a;}

};

struct R {

int val;

R(int v):val(v){}

bool operator ()(const A & a) { return a>val;} };

int main() {

int t1[] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

list l1(t1, t1 + 10);

R r(4);l1.remove_if(r);

print(l1.begin(), l1.end()); cout<

return 0;

}

A.

program outputs: 1 2 3 4

B.

program outputs: 5 6 7 8 9 10

C.

program outputs: 1 2 3 4 5

D.

program outputs: 6 7 8 9 10

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

#include

#include

#include

using namespace std;

int main () {

int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};

vector v (t,t+15);

int number = count(v.begin(), v.end(), 2);

cout<< number<

return 0;

}

Program outputs:

A.

4

B.

3

C.

2

D.

0

E.

compilation error

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

#include

#include

#include

#include

#include

using namespace std;

class compare {

bool reverse;

public:

compare(bool revparam = false){ reverse = revparam;}

bool operator()(int lhs, int rhs) const{

if (reverse)return (lhs > rhs);

elsereturn (lhs < rhs);

}

};

int main(){

int myints[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };

priority_queue > first(myints, myints + 10);

priority_queue, compare> second(myints, myints + 10,

compare(false));

while (first.size() > 0){

cout << first.top() << " "; first.pop();

}

while (second.size() > 0) {

cout << second.top() << " ";second.pop();

}

return 0;

}

A.

compilation error

B.

program outputs: 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0

C.

program outputs: 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9

D.

program outputs: 3 4 2 1 6 5 7 9 8 0 3 4 2 1 6 5 7 9 8 0

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

#include

#include

#include

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

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out; Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};

deque d1(t, t+10);

sort(d1.begin(), d1.end());

pair ::iterator, deque::iterator > result = equal_range(d1.begin(), d1.end(), B(20));

for_each(result.first, result.second, Out(cout));cout<

return 0;

}

Program outputs:

A.

10 10 10 20 20 20 20 30 30 30

B.

20 20 20 20

C.

10 20 20 20 20

D.

20 20 20 20 30

E.

10 20 20 20 20 30

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

#include

#include

#include

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

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

sort(d1.begin(), d1.end());

deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4), greater());

for_each(it, d1.end(), Out(cout)); cout<

return 0;

}

Program outputs:

A.

5 6 7 8 9 10

B.

4 5 6 7 8 9 10

C.

compilation error

D.

1 2 3 4 5

E.

1 2 3 4

Page: 3 / 4
Total 228 questions
Copyright © 2014-2025 Solution2Pass. All Rights Reserved