Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <queue>
    using namespace std;
    int main ()
    {
    queue<int> QueueData;
    int add (0);
    for (int k = 1; k <= 50; k++)
    QueueData.push(k);
    while (!QueueData.empty())
    {
    add += QueueData.front();
    QueueData.pop();
    }
    cout << add << endl;
    return 0;
    }
    1. 75
    2. 1275
    3. 12
    4. Compilation Error
    5. None of these
Correct Option: B

In this program, We used the push and pop operation of quueue to find out the total of all the number from 1 to 50.



Your comments will be displayed only after manual approval.