Last Update 4 hours ago Total Questions : 228
The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 4 hours ago. Deciding to include CPP practice exam questions in your study plan goes far beyond basic test preparation.
You'll find that our CPP exam questions frequently feature detailed scenarios and practical problem-solving exercises that directly mirror industry challenges. Engaging with these CPP sample sets allows you to effectively manage your time and pace yourself, giving you the ability to finish any C++ Certified Professional Programmer practice test comfortably within the allotted time.
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;
}
What happens when you attempt to compile and run the following code?
#include < vector >
#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(v1.rbegin(), v1.rend(), Sequence(1));
rotate(v1.begin(),v1.begin() + 1, v1.end() );
for_each(v1.begin(), v1.end(), Out < int > (cout) );cout < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < deque >
#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() {
int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};
deque < B > d1(t, t+10);
sort(d1.begin(), d1.end());
pair < deque < B > ::iterator, deque < B > ::iterator > result = equal_range(d1.begin(), d1.end(), B(20));
for_each(result.first, result.second, Out < B > (cout));cout < < endl;
return 0;
}
Program outputs:
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[]={5,6,8,2,1};
vector < B > v1(10,0);
sort(t1, t1+5);
sort(t2, t2+5);
set_intersection(t1,t1+5,t2,t2+5,v1.begin());
for_each(v1.begin(), v1.end(), Out < B > (cout));cout < < endl;
return 0;
}
Program outputs:
What happens 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"};
map < 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(map < int, string > ::iterator i=m.begin();i!= m.end(); i++) {
cout < < i? > second < < " ";
}
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < map >
#include < vector >
#include < sstream >
#include < string >
using namespace std;
int main(){
int t[] = { 3, 4, 2, 1, 0, 1, 2, 3, 4, 0 };
vector < int > v(t, t+10);
multimap < int,string > m;
for(vector < int > ::iterator i=v.begin(); i!=v.end(); i++) {
stringstream s; s < < *i < < *i; m.insert(pair < int,string > (*i,s.str()));
}
for(multimap < int, string > ::iterator i=m.begin();i!= m.end(); i++) {
cout < < *i < < " ";
}
return 0;
}
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:
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1.1 2.2 3.3 < enter > ?
#include < iostream >
#include < string >
using namespace std;
int main ()
{
int a,b,c;
cin > > a > > b > > c;
cout < < a < < b < < c < < endl;
return 0;
}
Program will output:
