×

Special Offer! Black Friday + Cyber Monday Sale! Extra 20% OFF - Ends In Coupon code: HELLO20OFF

Free CPP-22-02 Mock Exam – Practice Online Confidently

Increase your chances of passing the C++ Institute CPP-22-02 exam questions on your first try. Practice with our free online CPP-22-02 exam mock test designed to help you prepare effectively and confidently.

Exam Code: CPP-22-02
Exam Questions: 230
CPP - C++ Certified Professional Programmer
Updated: 25 Nov, 2025
Question 1

What happens when you attempt to compile and run the following code?
 #include <vector>
 #include <set>
 #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);
 generate_n(v1.begin(), 10, Sequence(1));
 random_shuffle(v1.rbegin(), v1.rend());
 sort(v1.begin(), v1.end(), great<int>());
 for_each(v1.begin(), v1.end(), Out<int>(cout));cout<<endl;
 return 0;
 }
Program outputs:

Options :
Answer: C

Question 2

What happens when you attempt to compile and run the following code?
 #include <vector>
 #include <iostream>
 #include <algorithm>
 using namespace std;
 template<typename T>class B { T val;
 public:
 B(T v):val(v){}
 T getV() const {return val;} bool operator < (const B & v) const { return val<v.val;} };
 template<class T>ostream & operator <<(ostream & out, const B<T> & 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<<" "; } };
 bool Less(const B<float> &a, const B<float> &b) { return int(a.getV())<int(b.getV());}
 int main() {
 float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};
 vector<B<float> > v1; v1.assign(t, t+10);
 stable_sort(v1.begin(), v1.end(), Less);
 for_each(v1.begin(), v1.end(), Out<B<float> >(cout));cout<<endl;
 return 0;
 }
Program outputs:

Options :
Answer: A

Question 3

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};
 int t2[]={5,6,8,2,1};
 vector<B> v1(10,0);
 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<B>(cout));cout<<endl;
 return 0;
 }
Program outputs:

Options :
Answer: A

Question 4

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:

Options :
Answer: A

Question 5

What will happen when you attempt to compile and run the following code?
 #include <iostream>
 #include <string>
 using namespace std;
 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<string>a("Hello"); string s(" world!");
 a.add(s);
 cout << a.getV() <<endl;
 return 0;
 }

Options :
Answer: A

Viewing Page : 1 - 23
Practicing : 1 - 5 of 230 Questions

© Copyrights FreeMockExams 2025. All Rights Reserved

We use cookies to ensure that we give you the best experience on our website (FreeMockExams). If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the FreeMockExams.