Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector;
7.
int sum (0);
8.
myvector.push_back (100);
9.
myvector.push_back (200);
10.
myvector.push_back (300);
11.
while (!myvector.empty())
12.
{
13.
sum += myvector.back();
14.
myvector.pop_back();
15.
}
16.
cout
Options:
A .  500
B .  600
C .  700
D .  Error
Answer: Option B

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.
Output:
$ g++ vect1.cpp
$ a.out
600



Was this answer helpful ?

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers