Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> VectorData;
    int add (0);
    VectorData.push_back (50);
    VectorData.push_back (150);
    VectorData.push_back (200);
    while (!VectorData.empty())
    {
    add += VectorData.back();
    VectorData.pop_back();
    }
    cout << add << '\n';
    return 0;
    }
    1. 50
    2. 150
    3. 200
    4. 400
    5. None of these
Correct Option: D

In this program, We are forming a stack and adding the elements and We are finding the total number of elements that are in stack.



Your comments will be displayed only after manual approval.