Free CPP Exam Braindumps

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



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

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

int main ()
{
int t[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector<int> v1(t, t + 10);
deque<int> d1(v1.begin(), v1.end());
deque<int> d2;
d2 = d1;
d2.insert(d1.rbegin(), 10);
for(int i = 0; i<d1.size(); i++)
{
cout<<d1[i]<<" ";
}
return 0;
}

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

Answer(s): D






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

CPP Exam Discussions & Posts