Free CPP Exam Braindumps (page: 11)

Page 10 of 58

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

#include <iostream>
using namespace std;
int main()
{
cout<<100<<" ";
cout.setf(ios::hex);
cout<<100<<" ";
return 0;
}

Program outputs:

  1. 100 64
  2. 100 0x64
  3. 0x64 0x64
  4. 64 0x64
  5. 100 100

Answer(s): E



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

#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout<<100<<" ";
cout.flags(ios::showbase);
cout<<100<<" ";
return 0;
}

Program outputs:

  1. 64 64
  2. 64 0x64
  3. 0x64 0x64
  4. 64 100
  5. compilation error

Answer(s): D



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

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

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

vector<int>::iterator it = search_n(v.begin(), v.end(), 4, 2);
cout<< it?v.begin()<<endl;
return 0;
}

Program outputs:

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

Answer(s): D



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

#include <deque>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
template<typename T>
void print(T start, T end)
{
while (start != end)
cout<<*start++;
}
int main ()
{
string t[] = {"one", "two" ,"three" ,"four", "five"};
vector<string> v1(t, t+5);
deque<string> d1(v1.rbegin(), v1.rend());
d1.push_back("zero");
print(d1[0].rbegin(),d1[0].rend());

return 0;
}

  1. program outputs: orez
  2. program outputs: evif
  3. compilation error
  4. program outputs: five

Answer(s): B






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

CPP Exam Discussions & Posts