Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    bool IsOdd (int k)
    {
    return ((k % 2) == 1);
    }
    int main ()
    {
    vector<int> num;
    num.push_back(110);
    num.push_back(45);
    num.push_back(85);
    num.push_back(101);
    vector<int> :: iterator Iter = find_if (num.begin(),
    num.end(), IsOdd);
    cout << *Iter << '\n';
    return 0;
    }
    1. 110
    2. 85
    3. 101
    4. 45
    5. None of these
Correct Option: D

In this program, We used find_if method and returned the first odd value in the vector.



Your comments will be displayed only after manual approval.