New Year Special 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: save70

Full Access C++ Institute CPP Tutorials

Page: 5 / 9
Total 228 questions

C++ Certified Professional Programmer Questions and Answers

Question 17

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

#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 v (t,t+15);

vector::iterator it = search_n(v.begin(), v.end(), 4, 2);

cout<< it?v.begin()<

return 0;

}

Program outputs:

Options:

A.

10

B.

3

C.

1

D.

15

E.

compilation error

Question 18

What will happen when you attempt to compile and run the following code? Choose all possible answers.

#include

using namespace std;

class B {};

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T a) { _v+=a; }

};

int main()

{

A a(1);

Ab;

a.add(10);

cout << a.getV() <

return 0;

}

Options:

A.

program will display:11

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Question 19

Which keywords can be used to define template type parameters? Choose all possible answers:

Options:

A.

class

B.

typedef

C.

typename

D.

static

E.

volatile

Question 20

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

#include

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T & a) { _v+=a; }

};

int main()

{

Aa("Hello");

string s(" world!");

a.add(s);

cout << a.getV() <

return 0;

}

Options:

A.

program will display: Hello world!

B.

program will not compile

C.

program will display: Hello

D.

program will run without any output

Page: 5 / 9
Total 228 questions