Master CPP-22-02 in 2026 with the Latest Dumps (V8.02) + Free C++ Certified Professional Programmer CPP-22-02 Free Dumps (Part 2, Q41-Q85)

Effective CPP – C++ Certified Professional Programmer exam preparation starts with DumpsBase’s CPP-22-02 dumps (V8.02) today. All the CPP-22-02 exam questions in V8.02 are created and reviewed by certified experts, ensuring accuracy and relevance to the current exam format. We have previously shared the CPP-22-02 free dumps (Part 1, Q1-Q40) of V8.02, so you can trust that our dumps provide a structured learning experience, helping you focus on the areas that matter most—from STL containers and algorithms to smart pointers, templates, and modern C++ features. With these CPP-22-02 dumps featuring 228 practice questions, you can track your progress, identify weak areas, and strengthen your understanding through continuous practice. So choose DumpsBase now. This not only helps you earn the C++ Certified Professional Programmer certification but also positions you ahead in the competitive programming industry.

Today, we will continue to share the CPP-22-02 free dumps (Part 2, Q41-Q85) of V8.02 online:

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

#include <iostream>

#include <algorithm>

#include <vector>

#include <deque>

#include <set>

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

deque<int> d1(t, t + 10);

set<int> s1(t, t + 10);

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

for_each(d1.begin(), d1.end(), myfunction); // Line II

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

return 0;

}

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

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

template<class T>struct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

int main() {

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

vector<B> v1(t,t+10);

sort(v1.begin(), v1.end(), greater<B>());

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

return 0;

}

Program outputs:

3. 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.fail() ; ) {

int i;

f>>i;

l.push_back(i);

}

f.close();

for_each(l.begin(), l.end(), Out<int>(cout));

return 0;

}

Programwill output:

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

#include <deque>

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

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

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<B> d1(t, t+10);

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

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

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

return 0;

}

Program outputs:

5. 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,2,3,5,1,2,7,3,2,1,10, 4,4,5};

vector<int> v (t,t+15);

vector<int>::iterator it = search_n(v.begin(), v.end(), 4, 2);

cout<< it?v.begin()<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

#include <algorithm>

#include <set>

using namespace std;

class A {

int a;

public:

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

int getA() const { return a; } void setA(int a) { this?>a = a; }

operator int() const {return a;}

};

int main () {

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

set<A> s (t,t+15);

cout<<equal(s.begin(), s.end(), t)<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

#include <set>

#include <vector>

using namespace std;

template<class T> void print(T start, T end) {

while (start != end) {

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

}

}

int main(){

vector<int>v;

multiset<int> s;

for(int i=10; i>0; i??) {

v.push_back(i); s.push_back(i);

}

print(v.begin(), v.end()); print(s.begin(), s.end());cout<<endl;

return 0;

}

8. 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<<" "; } };

struct Sequence { int start;

Sequence(int start):start(start){}

int operator()() {return 10*(1+(start++ %3));}

};

int main() {

deque<int> d1(10);

generate(d1.begin(), d1.end(), Sequence(1));

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

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

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

return 0;

}

Program outputs:

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

#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

bool classifier(int v) {

return v%2==0;

}

int main() {

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

vector<int> v1(t, t+10);

set<int> s1(t, t+10);

replace(v1.begin(), v1.end(),classifier, 10);

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:

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

#include <vector>

#include <set>

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

};

bool predicate(int v) { return v%2==0; }

int main() {

vector<int> v1(10);

generate_n(v1.begin(), 10, Sequence(1));

set<int> s1(v1.begin(), v1.end());

remove_if(s1.begin(), s1.end(), predicate);

for_each(s1.begin(), s1.end(), print);cout<<endl;

return 0;

}

Program outputs:

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

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

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_intersection(t1,t1+5,t2,t2+5,v1.begin());

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

return 0;

}

Program outputs:

12. Which method added to class B at the marked spot will allow the code below to compile? Choose

all possible solutions.

#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

/* Insert Code Here */

};

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

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

vector<B> v1(t, t+10);

sort(v1.begin(), v1.end(), greater<B>());

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

return 0;

}

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

#include <iostream>

#include <algorithm>

#include <set>

using namespace std;

class A {

int a;

public:

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

int getA() const { return a; } void setA(int a) { this?>a = a; }

bool operator < (const A & b) const { return a<b.a;}

};

struct Compare {

bool operator ()(A & a) {

if (a.getA() < 5) return true;

return false;

}

};

int main () {

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

set<A> d (t,t+15);

int number = count_if(d.begin(), d.end(), Compare());

cout<< number<<endl;

return 0;

}

Program outputs:

14. 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<enter>?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

int a,b,c;

cin>>a>>b>>c;

cout<<a<<b<<c<<endl;

return 0;

}

Program will output:

15. 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>

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

#include <vector>

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

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() {

return start++; } };

int main() {

vector<int> v1(10);

vector<int> v2(10);

generate(v1.begin(), v1.end(), Sequence(1));

reverse_copy(v1.begin(),v1.end(), v2.rbegin());

sort(v2.begin(), v2.end(), less_equal<int>());

for_each(v2.begin(), v2.end(), Out<int>(cout) );cout<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

using namespace std;

void g(int a)

{

cout<<a?1<<endl;

}

template<class A>

void g(A a)

{

cout<<a+1<<endl;

}

int main()

{

int a = 1;

g(a);

return 0;

}

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

#include <deque>

#include <iostream>

#include <algorithm>

#include <set>

using namespace std;

template<class T>struct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; }

};

bool Compare(char a, char b) { return tolower(a) < tolower(b);}

int main() {

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout<<includes(s,s+6, t1,t1+3, Compare)<<" "<<includes(s,s+6, t2,t2+3, Compare)<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

#include <set>

#include <vector>

using namespace std;

int main(){

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

vector<int>v(t, t+10);

multiset<int> s1(v.begin(),v.end());

s1.insert(v.begin(),v.end());

pair<multiset<int>::iterator,multiset<int>::iterator> range;

range = s1.equal_range(6);

while (range.first != range.second) {

cout<<*range.first<<" "; range.first++;

}

return 0;

}

20. 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;

}

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

#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

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

set<int> s1(t, t+10);

vector<int> v1(s1.rbegin(), s1.rend());

swap_ranges(s1.begin(), s1.end(), v1.begin());

for_each(v1.begin(), v1.end(), myfunction);

for_each(s1.begin(), s1.end(), myfunction);

return 0;

}

Program outputs:

22. 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);

deque<int>::iterator it = lower_bound(d1.begin(), d1.end(), 4);

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

return 0;

}

Program outputs:

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

#include <iostream>

using namespace std;

template<class A>

void f(A a)

{

cout<<1<<endl;

}

void f(int a)

{

cout<<2<<endl;

}

int main()

{

int a = 1;

f<float>(a);

return 0;

}

24. 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 = 10; i>0; i??)

{

v1.push_back(i);

}

std::vector<int>::iterator it = v1.begin();

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<<sum <<std::endl;

return 0;

}

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

#include <vector>

#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[]={3,2,4,1,5,10,9,7,8,6};

vector<int> v1(t,t+10);

sort(v1.begin(), v1.end(), greater<int>());

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

return 0;

}

Program outputs:

26. Which changes introduced independently will allow the code to compile and display “one” “eight”

“nine” “ten”? Choose all that apply.

#include <iostream>

#include <map>

#include <string>

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(){

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

string s[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","ten"};

multimap<A,string> m;/* Replace Code Here 3 */

for(int i=0; i<10; i++) {

m.insert(pair<A,string>(A(t[i]),s[i]));

}

m.erase(m.lower_bound(2),m.upper_bound(7));

multimap<A, string>::iterator i=m.begin();/* Replace Code Here 4 */

for( ; i!= m.end(); i++) {

cout<<i?>second<<" ";

}

cout<<endl;

return 0;

}

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

#include <vector>

#include <iostream>

#include <algorithm>

#include <functional>

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 t1[]={1,2,3,4,5,6,7,8,9,10};

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

vector<int> v1(t1, t1+10);

vector<int> v2(t2, t2+10);

vector<int> v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus<int>());

for_each(v3.rbegin(), v3.rend(), Out<int>(cout));cout<<endl;

return 0;

}

Program outputs:

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

#include <vector>

#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<<" ";

}

};

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() { return 10*(1+(start++ %3)); } };

int main() {

vector<int> v1(10);

vector<int> v2(10);

generate(v1.begin(), v1.end(), Sequence(1));

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

unique_copy(v1.begin(),v1.end(), v2.begin());

for_each(v2.begin(), v2.end(), Out<int>(cout) );cout<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

#include <algorithm>

#include <map>

using namespace std;

int main() {

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

map<int, int> m;

for(int i=0; i < 10; i++) {

m[i]=t[i];

}

map<int, int>::iterator it = find(m.begin(), m.end(), 5);

cout<<it?>first;

return 0;

}

Program outputs:

30. 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:

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

#include <vector>

#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 t1[]={3,2,4,1,5};

int t2[]={5,6,8,2,1};

vector<int> v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

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

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

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[]={6,10,8,7,9};

vector<B> 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<B>(cout));cout<<endl;

return 0;

}

Program outputs:

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

#include <vector>

#include <iostream>

#include <algorithm>

#include <functional>

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[]={3,2,4,1,5,6,10,8,7,9};

vector<int> v1(t, t+10);

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

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

return 0;

}

Program outputs:

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

#include <iostream>

#include <set>

#include <vector>

using namespace std;

int main(){

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

vector<int>v(t, t+10);

set<int> s1(v.begin(),v.end());

s1.insert(v.begin(),v.end());

bool found = s1.find(7);

if (found){

cout<<"Element found!n";

}else {

cout<<"Element not found!n";

}

return 0;

}

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

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

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_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());

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

return 0;

}

Program outputs:

36. What will happen when you attempt to compile and run the code below, assuming that you enter

the following sequence: 1 2 3 end<enter>?

#include <iostream>

#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 ()

{

list<int> l;

for( ; !cin.bad() ; )

{

int i;

cin>>i;

l.push_back(i);

}

for_each(l.begin(), l.end(), Out<int>(cout));

return 0;

}

Program will output:

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

#include <vector>

#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 t1[]={3,2,4,1,5};

int t2[]={5,6,8,2,1};

vector<int> v1(10);

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<int>(cout));cout<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

using namespace std;

int main()

{

cout<<100<<" ";

cout.setf(ios::hex);

cout<<100<<" ";

return 0;

}

Program outputs:

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

#include <vector>

#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 t1[]={3,2,4,1,5};

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

vector<int> 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<int>(cout));cout<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

#include <map>

#include <vector>

#include <sstream>

#include <string>

using namespace std;

int main(){

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

vector<int> v(t, t+10);

map<int,string> m;

for(vector<int>::iterator i=v.begin(); i!=v.end(); i++) {

stringstream s; s<<*i<<*i; m.insert(pair<int,string>(*i,s.str()));

}

for(map<int, string>::iterator i=m.begin();i!= m.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

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

#include <vector>

#include <iostream>

#include <algorithm>

#include <functional>

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 t1[]={3,2,4,1,5};

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

vector<int> v1(5);

transform(t1,t1+5,t2,v1.rbegin(), plus<int>());

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

return 0;

}

Program outputs:

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

#include <vector>

#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[]={3,2,4,1,5,10,9,7,8,6};

vector<int> v1(t,t+10);

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

return 0;

}

Program outputs:

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

#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

using namespace std;

int main() {

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

vector<int> v1(t, t + 15);

set<int> s1(t, t + 15);

pair<set<int>::iterator, vector<int>::iterator > resultSet = mismatch(s1.begin(), s1.end(),

v1.begin());

cout<<*resultSet.first<<" "<<*resultSet.second<<endl;

return 0;

}

Program outputs:

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

#include <iostream>

using namespace std;

template <typename T>

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T a) { _v+=a; }

template <class U>

U get(U a) {

return (U)(_v);

}

};

int main()

{

A<int> a(1);

a.add(10);

cout.setf( ios::showpoint);

cout << a.getV() << " " << a.get(1.0)<<endl;

return 0;

}

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

#include <list>

#include <vector>

#include <iostream>

using namespace std;

int main ()

{

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

vector<int>v1(t, t+5);

list<int>l1;

l1.assign(v1.end(), v1.begin());

for(int i=0; i<l1.size(); i++)

{

cout<<l1.at(i)<<" ";

}

cout<<endl;

return 0;

}


 

Pass CPP-22-02 Exam in 2026: Comprehensive C++ Certified Professional Programmer CPP-22-02 Dumps (V8.02) + Free Dumps (Part 1, Q1-Q40)

Add a Comment

Your email address will not be published. Required fields are marked *