View Single Post
  #2 (permalink)  
Old 12-01-2007, 11:02 PM
staykovmarin staykovmarin is offline
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Code:
for(int i=1;i<=10;i++) array[i] = i;
Yes, your has a size of 10 elements. However, when you are iterating trough the array, you are telling it to get the 1st trough the 10 element. Arrays have a 0 index, meaning that the first element is not the element at 1, but the element at zero. So array[1] will in fact give you the second element present, while array[0] will output the first element. Likewise, array[10] is going to look for the 11th element, which you dont have, while array[9] is going to give you the last element.
Reply With Quote