1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what is the ouput of this code???

Discussion in 'C' started by ghostonline, May 10, 2011.

  1. ghostonline

    ghostonline New Member

    Joined:
    May 10, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 = 2*myinventory[i -1];
    }
    myinventory.push_back(34);
    for (int i = 0; i < myinventory.size(); i++)
    {
    cout << myinventory<< " ";
    }

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

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page