C++ Institute C++ Certified Professional Programmer CPP Question # 53 Topic 6 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 53 Topic 6 Discussion

CPP Exam Topic 6 Question 53 Discussion:
Question #: 53
Topic #: 6

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

#include

#include <algorithm>

#include

#include

using namespace std;

void myfunction(int i) { cout << " " << i;

}

struct sequence {

int val,inc;

sequence(int s, int i):val(s),inc(i){}

int operator()(){

int r = val; val += inc;

return r;

}

};

int main() {

vector v1(10);

fill(v1.begin(), v1.end(), sequence(1,1));

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:


A.

1 2 3 4 5 6 7 8 9 10


B.

10


C.

0 0 0 0 0 0 0 0 0 0


D.

compilation error


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.