Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> firstRow (4, 15);
    vector<int> secondRow (4, 26);
    vector<int>::iterator iter;
    swap_ranges(firstRow.begin() + 1, firstRow.end() - 1, secondRow.begin());
    cout << "First Row contains:";
    for (iter = firstRow.begin(); iter != firstRow.end(); ++iter)
    cout << " " << *it;
    cout << "\nSecond Row contains:";
    for (it = secondRow.begin(); it != secondRow.end(); ++it)
    cout << " " << *it;
    return 0;
    }
    1. Second Row contains: 15 15 26 26
      First Row contains: 15 26 26 15
    2. First Row contains: 15 26 26 15
    3. First Row contains: 15 26 26 15
      Second Row contains: 15 15 26 26
    4. Second Row contains: 15 15 26 26
    5. None of these
Correct Option: C

In this program, We swapped the values according to their position.



Your comments will be displayed only after manual approval.