Free CPP Exam Braindumps
C++ Certified Professional Programmer Questions 106–110 (page: 23)

Updated On: 9-Feb-2026

What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3<enter>?

#include <iostream>

using namespace std;

int main ()
{
int a,b,c;
cin>>a>>b>>c;
cout<<a<<b<<c<<endl;
return 0;
}

Program will output:

  1. 123
  2. 1 2 3
  3. 321
  4. compilation error
  5. the result is unspecified

Answer(s): A



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;
}

  1. program outputs: zero one two three four five six seven eight nine
  2. program outputs: ten one two three four five six seven eight nine
  3. program outputs: zero eleven two three four five six seven eight nine
  4. program outputs: ten eleven two three four five six seven eight nine
  5. program outputs: 0 1 2 3 4 5 6 7 8 9

Answer(s): B



What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3<enter>?

#include <iostream>
#include <string>
#include <sstream>

using namespace std;
int main ()
{
string s;
getline(cin, s);
stringstream input(s);
stringstream output;

for( ; !input.fail() ; )
{
int i;
input>>i;
output<<hex<<i<<" ";
}
cout<<output.str();
return 0;
}

Program will output:

  1. 1 2 3
  2. 1 2 3 3
  3. 0x1 0x2 0x3
  4. 0x1 0x2 0x3 0x3
  5. program runs forever without output

Answer(s): B



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

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Compare {
bool operator ()(int a) {
if (a >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};
vector<int> v (t,t+15);

int number = count(v.begin(), v.end(), Compare());
cout<< number<<endl;
return 0;
}

Program outputs:

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

Answer(s): E



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

#include <deque>
#include <set>
#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[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};
deque<B> d1(t, t+10);
sort(d1.begin(), d1.end());
set<B> s1(t,t+10);
cout<<binary_search(s1.begin(),s1.end(), 4)<<" "<<binary_search(d1.begin(),d1.end(), 4)<<endl;
return 0;
}

Program outputs:

  1. 1 0
  2. 1 1
  3. true true
  4. false false
  5. compilation error

Answer(s): E



Viewing page 23 of 47
Viewing questions 111 - 115 out of 228 questions


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

AI Tutor AI Tutor 👋 I’m here to help!