Home » C++ Programming » Functions » Question
  1. What is the output of this program?
    #include <iostream>
    #include <functional>
    #include <vector>
    #include <algorithm>
    #include <string>
    using namespace std;
    int main ()
    {
    vector <string*> num;
    num.push_back ( new string ("First") );
    num.push_back ( new string ("Second") );
    num.push_back ( new string ("Third") );
    num.push_back ( new string ("Fourth") );
    num.push_back ( new string ("Fifth") );
    vector <int> lengths ( num.size() );
    transform (num.begin(), num.end(), lengths.begin(),
    mem_fun(&string :: length));
    for (int k = 0; k < 5; k++)
    {
    cout << lengths[k] << " ";
    }
    return 0;
    }
    1. 5 6 5 6 5
    2. 6 5 6 5
    3. 5 6 5
    4. 6 5
    5. 5
Correct Option: A

In this program, We calculated the number of letters in every string by using function objects.



Your comments will be displayed only after manual approval.