Exam Code: CPP-22-02
Exam Questions: 230
CPP - C++ Certified Professional Programmer
Updated: 05 Jan, 2026
Viewing Page : 1 - 23
Practicing : 1 - 5 of 230 Questions
Question 1

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 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 <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);
 sort(d1.begin(), d1.end());
 deque<int>::iterator it = upper_bound(d1.begin(), d1.end(), 4);
 for_each(it, d1.end(), Out<int>(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 <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 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 2026. 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.