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 myfunction (int k, int L)
    {
    return (k==L);
    }
    int main ()
    {
    int Array[] = {101, 202, 202, 202, 303, 303, 202, 202, 101};
    vector<int> num (Array, Array + 9);
    vector<int> :: iterator Iter;
    Iter = unique (num.begin(), num.end());
    num.resize( distance(num.begin(), Iter) );
    unique (num.begin(), num.end(), myfunction);
    for (Iter = num.begin(); Iter != num.end(); ++Iter)
    cout << ' ' << *Iter;
    return 0;
    }
    1. 101 202 303 202 101
    2. 101 202 303
    3. 101 202 303 202
    4. 101 202
    5. 101
Correct Option: A

In this program, We are printing only the unique values by comparing every value.



Your comments will be displayed only after manual approval.