Free C++ Institute CPP Exam Actual Questions

The questions for CPP were last updated On Jan 17, 2025

Question No. 1

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

#include

#include

#include

#include

using namespace std;

int main() {

int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};

vector v1(t, t + 15);

set s1(t, t + 15);

pair::iterator, vector::iterator > resultSet = mismatch(s1.begin(), s1.end(),

v1.begin());

cout<<*resultSet.first<<" "<<*resultSet.second<

return 0;

}

Program outputs:

Show Answer Hide Answer
Correct Answer: B

Question No. 2

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

#include

#include

using namespace std;

int main() {

int t[] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };

string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};

map m;

for (int i = 0; i < 10; i++) {

m.insert(pair(t[i], s[i]));

}

if (m.count(3) == 2) {

m.erase(3);

}

for (map::iterator i = m.begin(); i != m.end(); i++) {

cout << i?>first << " ";

}

return 0;

}

Show Answer Hide Answer
Correct Answer: A

Question No. 3

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

#include

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v=0):val(v){}

int getV() const {return val;}

B operator +(const B &b )const { return B(val + b.val);} };

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

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

int main() {

int t[]={1,2,3,4,5,6,7,8,9,10};

vector v1(t, t+10);

vector v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun(Add),1));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Show Answer Hide Answer
Correct Answer: D

Question No. 4

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

string t[]={"aaa","Aaa", "aAa","aaA","bbb","Bbb", "bBb", "bbB"};

vector v1(t, t+8);

sort(v1.begin(), v1.end());

for_each(v1.begin(), v1.end(), Out(cout));cout<

return 0;

}

Program outputs:

Show Answer Hide Answer
Correct Answer: A

Question No. 5

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

#include

using namespace std;

template

class A {

T_v;

public:

A(T v);

};

template

Show Answer Hide Answer
Correct Answer: B