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: 01 Apr, 2026
Question 1

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:

Options :
Answer: A

Question 2

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:

Options :
Answer: D

Question 3

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:

Options :
Answer: D

Question 4

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;
 }
 struct sequence {
 int val,inc;
 sequence(int s, int i):val(s),inc(i){}
 int operator()(){
 int r = val; val += inc;
 return r;
 }
 };
 int main() {
 vector<int> v1(10);fill(v1.begin(), v1.end(), sequence(1,1));
 for_each(v1.begin(), v1.end(), myfunction);
 return 0;
 }
Program outputs:

Options :
Answer: D

Question 5

What will be output of the program when you attempt to compile and run the following
code?
 #include <iostream>
 #include <map>
 #include <vector>
 #include <string>
 using namespace std;
 int main(){
 int second[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
 string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"};
 multimap<int,string> m;for(int i=0; i<10; i++) {
 m.insert(pair<int,string>(second[i],first[i]));
 }
 m[0]="ten";
 m.insert(pair<int,string>(1,"eleven"));
 for(multimap<int, string>::iterator i=m.begin();i!= m.end(); i++) {
 cout<<i?>second<<" ";
 }
 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.