Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   what is the ouput of this code??? (http://www.go4expert.com/forums/ouput-code-t25746/)

ghostonline 10May2011 16:22

what is the ouput of this code???
i cant seem to get this code to run and i need to know the output can some one plz help me ?

vector<int> myinventory(4);
myinventory[0] = 2;
for (int i = 1; i <= 3; i++)
myinventory[i] = 2*myinventory[i -1];
for (int i = 0; i < myinventory.size(); i++)
cout << myinventory[i]<< " ";

please if u can provide the output that would be great :happy:

xpi0t0s 11May2011 12:14

Re: what is the ouput of this code???
What errors do you get when you try to compile it?

But in any case, why can't you figure it out? The first line isn't exactly complicated. Neither is the second. The first for loop does something to the other elements not initialised in the second line. The next line - what does that do (hint: try RTFM)? And the last for loop is the display loop.

All times are GMT +5.5. The time now is 15:46.