Smartly Prepare Exam with Free Online CPP-22-02 Practice Test

We offer the latest CPP-22-02 practice test designed for free and effective online CPP - C++ Certified Professional Programmer certification preparation. It's a simulation of the real CPP-22-02 exam experience, built to help you understand the structure, complexity, and topics you'll face on exam day.

Exam Code: CPP-22-02
Exam Questions: 230
CPP - C++ Certified Professional Programmer
Updated: 08 Jul, 2025
Viewing Page : 1 - 23
Practicing : 1 - 5 of 230 Questions
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 <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;
 }

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};
 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 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;
 }
 int multiply (int a) {
 return a*2;
 }
 int main() {
 int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
 vector<int> v1(t, t+10);
 set<int> s1(t, t+10);
 transform(s1.begin(), s1.end(), v1.begin(), multiply);
 transform(v1.begin(), v1.end(), s1.begin(), multiply);
 for_each(s1.begin(), s1.end(), myfunction);
 return 0;
 }
Program outputs:

Options :
Answer: D

Question 5

What happens when you attempt to compile and run the following code?
 #include <iostream>
 using namespace std;
 int main ()
 {
 float f1 = 10.0;
 float f2 = 10.123;
 cout<<noshowpoint<<f1<<" "<<f2;
 return 0;
 }
Program outputs:

Options :
Answer: D

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

© Copyrights FreePDFQuestions 2025. All Rights Reserved

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