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: 06 Jan, 2026
Question 1

What happens when you attempt to compile and run the following code?
 #include <iostream>
 #include <algorithm>
 #include <vector>
 using namespace std;
 class A {
 int apublic:
 A(int a) : a(a) {}
 int getA() const { return a; } void setA(int a) { this?>a = a; }
 bool operator==(A & b) { return a == b.a; }
 };
 struct Compare{
 bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};
 };
 int main () {
 int t[] = {1,2,3,4,5,1,2,3,4,5};
 vector<A> v (t,t+10);
 vector<A>::iterator it;
 A m1[] = {A(1), A(2), A(3)};
 it = search (v.begin(), v.end(), m1, m1+3, Compare());
 cout << "First found at position: " << it?v.begin() << endl;
 return 0;
 }
Program outputs:

Options :
Answer: B

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 <iostream>
 #include <map>
 #include <string>
 using namespace std;
 int main(){
 int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 10 };
 string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};
 multimap<int,string> m;
 for(int i=0; i<10; i++) {
 m.insert(pair<int,string>(second[i],first[i]));
 }
 if (m[11] == "eleven") {
 cout<<"eleven ";
 }
 for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) {
 cout<<i?>second<<" ";
 }cout<<m.size();
 return 0;
 }

Options :
Answer: A

Question 4

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

Options :
Answer: A

Question 5

What happens when you attempt to compile and run the following code?
 #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()
 {
 int t1[] ={ 1, 7, 8, 4, 5 };
 list<int> l1(t1, t1 + 5);
 int t2[] ={ 3, 2, 6, 9, 0 };
 list<int> l2(t2, t2 + 5);
 l1.sort();
 list<int>::iterator it = l2.begin();
 it++; it++;
l1.splice(l1.end(),l2, it, l2.end());
 print(l1.begin(), l1.end()); cout<<"Size:"<<l1.size()<<" ";
 print(l2.begin(), l2.end()); cout<<"Size:"<<l2.size()<<endl;
 return 0;
 }

Options :
Answer: A

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

© Copyrights FreeMockExams 2026. 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.