arrays question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimgym1989
    New Member
    • Sep 2008
    • 30

    arrays question

    we have a question on our exam a couple of days ago..it is True or False.
    This is the question

    int[]list = new int[10];

    the statement

    list[5] = list[3] + list[2];

    updates the content of the fifth component of the array list.
    ------------------------------------------------------------------------------------------------------
    The correct answer here is False..the problem is I don't get it why is it False..
    can someone explain this to me.. :D
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    If you create an array of ints, all the ints in the array are initialized to zero.
    Adding zero and zero is zero and list[5] was zero before so nothing is updated.

    kind regards,

    Jos

    Comment

    • jimgym1989
      New Member
      • Sep 2008
      • 30

      #3
      Originally posted by JosAH
      If you create an array of ints, all the ints in the array are initialized to zero.
      Adding zero and zero is zero and list[5] was zero before so nothing is updated.

      kind regards,

      Jos
      thank my friend..
      you made my day great!! :)

      Comment

      • Laharl
        Recognized Expert Contributor
        • Sep 2007
        • 849

        #4
        Also, list[5] is the sixth element of list, since arrays are zero-indexed.

        Comment

        Working...