Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <functional>
    using namespace std;
    int op_increase (int k)
    {
    return ++k;
    }
    int main ()
    {
    vector<int> p;
    vector<int> q;
    for (int k = 0; k < 5; k++)
    p.push_back (k * 12);
    q.resize(p.size());
    transform (p.begin(), p.end(), q.begin(), op_increase);
    transform (p.begin(), p.end(), q.begin(), p.begin(), plus<int>());
    for (vector<int> :: iterator Iter = p.begin(); Iter != p.end(); ++Iter)
    cout << ' ' << *Iter;
    return 0;
    }
    1. 1 25
    2. 1 25 49
    3. 1 25 49 73
    4. 1 25 49 73 97
    5. Compilation Error
Correct Option: D

In this program, We allocated the values to the vector and then by using transform function, We increased the values.



Your comments will be displayed only after manual approval.