Last Update 10 hours ago Total Questions : 228
The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 10 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;
void g(int a)
{
cout < < a?1 < < endl;
}
template < class A >
void g(A a)
{
cout < < a+1 < < endl;
}
int main()
{
int a = 1;
g(a);
return 0;
}
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < set >
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this? > a = a; }
bool operator < (const A & b) const { return a < b.a;}
};
struct Compare {
bool operator ()(A & a) {
if (a.getA() < 5) return true;
return false;
}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set < A > d (t,t+15);
int number = count_if(d.begin(), d.end(), Compare());
cout < < number < < endl;
return 0;
}
Program outputs:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < map >
using namespace std;
int main() {
int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};
multimap < int, string > m;
for (int i = 0; i < 10; i++) {
m.insert(pair < int, string > (t[i], s[i] ));
}
if (m.count(3) == 2) {
m.erase(3);
}
for (multimap < int, string > ::iterator i = m.begin(); i != m.end(); i++) {
cout < < i? > first < < " ";
}
return 0;
}
What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three < enter > ?
#include < iostream >
#include < string >
using namespace std;
int main ()
{
string a;
cin.getline(a);
cout < < a < < endl;
return 0;
}
Program will output:
Which keywords can be used to define template type parameters? Choose all possible answers:
What happens when you attempt to compile and run the following code?
#include < iostream >
#include < algorithm >
#include < set >
using namespace std;
class A {
int a;
public:
A(int a) : a(a) {}
int getA() const { return a; } void setA(int a) { this? > a = a; }
operator int() const {return a;}
};
int main () {
int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};
set < A > s (t,t+15);
cout < < equal(s.begin(), s.end(), t) < < endl;
return 0;
}
Program outputs:
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 };
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;
}
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 < < " "; } };
int main() {
int t[]={3,2,4,1,5,10,9,7,8,6};
vector < int > v1(t,t+10);
sort(v1.begin(), v1.end(), greater < int > ());
cout < < min_element(v1.begin(), v1.end());
return 0;
}
Program outputs:
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;
}
struct sequence {
int val,inc;
sequence(int s, int i):val(s),inc(i){}
int operator()(){
int r = val; val += inc;
return r;
}
};
int main() {
vector < int > v1(10);
fill(v1.begin(), v1.end(), sequence(1,1));
for_each(v1.begin(), v1.end(), myfunction);
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;
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++; }
};
struct Odd { bool operator()(int v) { return v%2==0; } };
int main() {
vector < int > v1(10);
vector < int > v2(10);
generate(v1.begin(), v1.end(), Sequence(1));
stable_partition(v1.begin(),v1.end(), Odd());
for_each(v1.begin(), v1.end(), Out < int > (cout) );cout < < endl;
return 0;
}
Program outputs:
