Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int op_increase (int i)
{
    return ++i;
}
int main ()
{
    vector<int> a;
    vector<int> b;
    for (int i = 1; i < 4; i++)
    a.push_back (i * 10);
    b.resize(a.size());
    transform (a.begin(), a.end(), b.begin(), op_increase);
    transform (a.begin(), a.end(), b.begin(), a.begin(), plus<int>());
    for (vector<int> :: iterator it = a.begin(); it != a.end(); ++it)
        cout << ' ' << *it;
    return 0;
}

A. 21

B. 41

C. 61

D. 21 41 61

Answer: Option D


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it