C++ Certified Professional Programmer (CPP) - CPPL Actual Exam Questions
Last updated on May 14, 2026
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 }; 4XHVWLRQV�DQG�$QVZHUV�3') ������ 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; }
program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 Size:2
program outputs: 1 4 5 7 8 6 9 0 Size:8 3 2 6 9 0 Size:5
compilation error
program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 Size:2
program outputs: 0 1 4 5 6 7 8 9 Size:8 3 2 6 9 0 Size:5
to join the discussion
No discussions yet. Be the first to ask!
Delete Comment
Are you sure? This action cannot be undone.
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(a); return 0; }
program displays: 1
program displays: 2
compilation error
runtime exception 4XHVWLRQV�DQG�$QVZHUV�3') �������
to join the discussion
No discussions yet. Be the first to ask!
Delete Comment
Are you sure? This action cannot be undone.
4XHVWLRQV�DQG�$QVZHUV�3') ������ What happens when you attempt to compile and run the following code? #include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; class B { int val; public: B(int v=0):val(v){} int getV() const {return val;} operator int () const { return val;} }; template<class T>struct Out { ostream & out; Out(ostream & o): out(o){} void operator() (const T & val ) { out<<val<<" "; } }; struct Add : public binary_function<B, B, B> { B operator() (const B & a, const B &
1 2 3 4 5 6 7 8 9 10
const { return a+b; } }; int main() { B t[]={1,2,3,4,5,6,7,8,9,10}; vector<B> v1(t, t+10); vector<B> v2(10); transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), 1)); for_each(v2.rbegin(), v2.rend(), Out<B>(cout));cout<<endl; return 0; } Program outputs:
2 3 4 5 6 7 8 9 10 11
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2
compilation error
to join the discussion
No discussions yet. Be the first to ask!
Delete Comment
Are you sure? This action cannot be undone.
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=0):val(v){} int getV() const {return val;} }; ostream & operator <<(ostream & out, const B &
9 12 12 8 14
14 8 12 12 9
3 2 4 1 5 6 10 8 7 9
1 2 3 4 5 6 7 8 9 10
compilation error
{ 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(5); transform(t1,t1+5,t2,v1.rbegin(), plus<B>()); for_each(v1.rbegin(), v1.rend(), Out<int>(cout));cout<<endl; return 0; } Program outputs:
to join the discussion
No discussions yet. Be the first to ask!
Delete Comment
Are you sure? This action cannot be undone.
What happens when you attempt to compile and run the following code? #include <iostream> #include <algorithm> #include <vector> using namespace std; void myfunction(int
{ a*2; } int main() { int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 }; vector<int> v1(t, t+10); for_each(v1.begin(), v1.end(), multiply); iter_swap(v1.begin(),t+9); for_each(v1.begin(), v1.end(), myfunction); return 0; } Program outputs:
1 5 9 6 2 4 7 8 3 1
compilation error
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
10 5 9 6 2 4 7 8 3 1
{ cout << " " << i; } void multiply (int
to join the discussion
No discussions yet. Be the first to ask!
Delete Comment
Are you sure? This action cannot be undone.
Finish Practice?
Are you sure you want to finish? This will end your practice session.