Online Access Free CPP Exam Questions

Exam Code:CPP
Exam Name:C++ Certified Professional Programmer
Certification Provider:C++ Institute
Free Question Number:230
Posted:Aug 21, 2026
Rating
100%

Question 1

What happens when you attempt to compile and run the following code?
# include <vector>
# include <set>
# 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<<" ";
}
};
struct Sequence {
int start;
Sequence(int start):start(start){}
int operator()() {
return start++ ;
}
};
int main() {
vector<int> v1(5);
generate(v1.begin(), v1.end(), Sequence(1));
set<int> s1(v1.rbegin(), v1.rend());
deque<int> d1(s1.rbegin(), s1.rend());
reverse(v1.begin(),v1.end());
reverse(s1.begin(), s1.end());
reverse(d1.begin(), d1.end());
for_each(v1.begin(), v1.end(), Out<int>(cout) );
for_each(s1.begin(), s1.end(), Out<int>(cout) );
for_each(d1.begin(), d1.end(), Out<int>(cout) );cout<<endl;
return 0;
}
Program outputs:

Question 2

What happens when you attempt to compile and run the following code?
# include <list>
# include <vector>
# include <iostream>
using namespace std;
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5};
vector<int>v1(t, t+5);
list<int>l1;
l1.assign(v1.end(), v1.begin());
for(int i=0; i<l1.size(); i++)
{
cout<<l1.at(i)<<" ";
}
cout<<endl;
return 0;
}

Question 3

What happens when you attempt to compile and run the following code?
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;
bool identical(int a, int b) {
return b == 2*a?true:false;
}
int main() {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};
vector<int> v1(t, t + 15);
deque<int> d1(u, u + 15);
pair<deque<int>::iterator, vector<int>::iterator > result;
result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I if (result.first == d1.end() && result.second == v1.end()) {//Line II
cout<<"Identical\n";
} else {
cout<<"Not identical\n";
}
return 0;
}
Program outputs:

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 main() {
vector<int> v1(10,1);
fill(v1.begin()+2, v1.end()?2,2);
fill_n(v1.begin()+4,2,3);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}
Program outputs:

Question 5

What happens when you attempt to compile and run the following code?
#include <vector>
#include <iostream>
using namespace std;
class A
{
int a,b;
public:
A & operator =(const A & c) { a = c.a; return *this;}
A():a(0),b(0){}
void setA(int a) {this?>a = a;} void setB(int b) {this?>b = b;}
int getA() {return a;} int getB() {return b;}
};
int main ()
{
vector<A>v;
A a;
a.setA(10); a.setB(11);
v.push_back(a);
A b = v.front(); v.pop_back();
cout<<b.getB()<<" "<<b.getA()<<endl;
return 0;
}

Add Comments

Your email address will not be published. Required fields are marked *

insert code
Type the characters from the picture.