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 Function(int k, int L)
    {
    return (k < L);
    }
    struct ObjectClass {
    bool operator() (int k, int L)
    {
    return (k < L);
    }
    } StructObject;
    int main ()
    {
    int arr[] = {112, 125, 101};
    vector<int> Number(arr, arr + 3);
    sort (Number.begin(), Number.begin() + 2);
    sort (Number.begin() + 1, Number.end(), Function);
    sort (Number.begin(), Number.end(), StructObject);
    for (vector<int> :: iterator Iter = Number.begin(); Iter != Number.end(); ++Iter)
    cout << ' ' << *Iter;
    return 0;
    }
    1. 101 112 125
    2. 101 112
    3. 101
    4. Compilation Error
    5. None of these
Correct Option: A

In this style algorithm, We have sorted the elements in the vector by using the sort method.



Your comments will be displayed only after manual approval.