adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <vector> 
    #include <algorithm>
    #include <iostream>
    #include <iterator>
    using namespace std;
    int square(int i) { return i * i; }
    int main()
    {
        vector<int> V, V2;
        V.push_back(0);
        V.push_back(1);
        V.push_back(2);
        transform(V.begin(), V.end(), back_inserter(V2), square);
        copy(V2.begin(), V2.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    }

a.

0

b.

1

c.

2

d.

0 1 4

Answer: (d).0 1 4

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?