C++ Institute CPP Exam Questions
C++ Certified Professional Programmer (Page 8 )

Updated On: 10-Mar-2026

What happens when you attempt to compile and run the following code?

#include <deque>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; }
};
bool Compare(char a, char b) { return tolower(a) < tolower(b);}
int main() {
char s[]={"qwerty"};
char t1[]={"ert"};
char t2[]={"ERT"};
sort(s, s+6);
cout<<includes(s,s+6, t1,t1+3, Compare)<<" "<<includes(s,s+6, t2,t2+3, Compare)<<endl;
return 0;
}

Program outputs:

  1. 0 0
  2. 0 1
  3. 1 0
  4. 1 1

Answer(s): D



What happens when you attempt to compile and run the following code?

#include <vector>
using namespace std;
int main ()
{
std::vector<int> v1;
v1.push_back(10);
return 0;
}

  1. compilation fails due to error in line 2
  2. compilation fails due to error in line 5
  3. exception is thrown during run time
  4. code compiles and executes successfully

Answer(s): D



What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
int t[] = { 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };
vector<int> v(t, t+10);
set<int> s1(v.begin(),v.end());
s1.insert(v.begin(),v.end());
bool found = s1.find(7);
if (found){
cout<<"Element found!\n";
}else {
cout<<"Element not found!\n";
}
return 0;
}

  1. program will display "Element found!"
  2. program will display "Element not found!\n"
  3. code will not compile
  4. changing type of variable found to int will make this code compile

Answer(s): C



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;
}
bool classifier(int v) {
return v%2==0;
}
int main() {
int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };
vector<int> v1(t, t+10);
set<int> s1(t, t+10);
replace(v1.begin(), v1.end(),classifier, 10);
for_each(v1.begin(), v1.end(), myfunction);
return 0;
}

Program outputs:

  1. 1 5 10 5 10 10 10 3 3 1
  2. 1 5 2 5 2 4 4 3 3 1
  3. compilation error
  4. 10 10 2 10 2 4 4 10 10 10

Answer(s): C



What happens when you attempt to compile and run the following code?

#include <deque>
#include <list>
#include <iostream>
using namespace std;
int main ()
{
list<int> l1;
deque<int> d1;
for(int i=0; i<5; i++)
{
l1.push_back(i);l1.push_front(i);
d1.push_back(i);d1.push_front(i);
}
for(int i=0; i<d1.size(); i++)
{
cout<<d1[i]<<" "<<l1[i]<<" ";
}
cout<<endl;
return 0;
}

  1. program displays 4 4 3 3 2 2 1 1 0 0 0 0 1 1 2 2 3 3 4 4
  2. runtime exception
  3. compilation error due to line 11
  4. compilation error due to line 12
  5. compilation error due to line 16

Answer(s): E



Viewing page 8 of 47
Viewing questions 36 - 40 out of 228 questions



Post your Comments and Discuss C++ Institute CPP exam dumps with other Community members:

CPP Exam Discussions & Posts

AI Tutor