Results 1 to 18 of 18

Thread: Confused about using arrays

Threaded View

  1. #4

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    int billy [] = {16, 2, 77, 40, 12071};
    int n, result=0;

    int main ()
    {
    for ( n=0 ; n<5 ; n++ )
    {
    result += billy[n];
    }
    cout << result;
    return 0;
    }

    result = 12206

    I was trying to figure out why in the for loop isn't n<5 instead n<=5 because there are 5 elements in the array.

    I am thinking that the computer sees billy[n] as billy[0], billy[1], billy[2] . . .etc. when the loop is done. Am I right?
    Last edited by aewarnick; Jan 5th, 2003 at 03:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width