Free CPP Exam Braindumps
C++ Certified Professional Programmer Questions 86–90 (page: 19)

Updated On: 9-Feb-2026

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

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

using namespace std;

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

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

What will be the result assuming that user will enter following sequence: 64 100:

  1. 64 100
  2. 100 256
  3. 100 256 256
  4. 0x64 0x100
  5. 0x100 0x256 0x256

Answer(s): C



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

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
template<class T>struct Out {
ostream & out;
Out(ostream & o): out(o){}
void operator() (const T & val ) { out<<val<<" "; } };

int Add(int a, int b) {
return a+b;
}

int main() {
int t[]={1,2,3,4,5,6,7,8,9,10};
vector<int> v1(t, t+10);
vector<int> v2(10);
transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun (Add),1));
for_each(v2.rbegin(), v2.rend(), Out<int>(cout));cout<<endl;
return 0;
}

Program outputs:

  1. 1 2 3 4 5 6 7 8 9 10
  2. 2 3 4 5 6 7 8 9 10 11
  3. 10 9 8 7 6 5 4 3 2 1
  4. 11 10 9 8 7 6 5 4 3 2
  5. compilation error

Answer(s): D



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:

  1. 8 10 5 1 4 6 2 7 9 3
  2. 1 2 3 4 5 6 7 8 9 10
  3. compilation error
  4. 10 9 8 7 6 5 4 3 2 1

Answer(s): C



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

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

void myfunction(pair<int, int> i) {
cout << " " << i.first;
}

int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
map<int, int> m;
for(int i=0; i < 10; i++) {
m[i]=t[i];
}

for_each(m.begin(), m.end(), myfunction);
return 0;
}

Program outputs:

  1. 10 5 9 6 2 4 7 8 3 1
  2. 0 1 2 3 4 5 6 7 8 9
  3. 9 8 7 6 5 4 3 2 1 0
  4. 1 3 8 7 4 2 6 9 5 10
  5. compilation error

Answer(s): B



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

#include <iostream>
using namespace std;
int main()
{
cout<<true<<" "<<boolalpha<<false;
return 0;
}

Program outputs:

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

Answer(s): C



Viewing page 19 of 47
Viewing questions 91 - 95 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!