Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <stack>
    using namespace std;
    int main ()
    {
    stack<int> StackData;
    cout << (int) StackData.size();
    for (int k =0; k < 5; k++)
    {
    StackData.push(k);
    cout << " ";
    cout << (int) StackData.size() << " ";
    }
    return 0;
    }
    1. 0 1
    2. 0 1 2
    3. 0 1 2 3
    4. 0 1 2 3 4
    5. 0 1 2 3 4 5
Correct Option: E

In this program, We declared myints and not initialized in first option, So it’s value is 0 and on another, We are pushing 5 values, So it’s size is 5.



Your comments will be displayed only after manual approval.