adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
        vector<int> myvector;
        int sum (0);
        myvector.push_back (100);
        myvector.push_back (200);
        myvector.push_back (300);
        while (!myvector.empty())
        {
            sum += myvector.back();
            myvector.pop_back();
        }
        cout << sum << '\n';
        return 0;
    }

a.

500

b.

600

c.

700

d.

Error

Answer: (b).600

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?