0

shouldn't an array of integers containing 9 elements be int a[8]; as the array starts from 0. and 0 to 8 would be 9 elements. please explain.

21st Sep 2016, 2:45 AM
Rick
3 Réponses
+ 2
Rickin you asked a good question ... actually we start counting memory from 0 .. but the integer value within [] depends upon the number of elements ...
21st Sep 2016, 5:49 AM
Descifrador
Descifrador - avatar
+ 1
you tell the size of the array here int x[5] but you will call them from 0 to x-1 and they are just numbers don't forget: the members numbers are from 0 because it's the distance from the first of the array! good luck!
26th Sep 2016, 8:11 PM
Ayin GhaziMoradi
0
When defining the array you should specify the number of elements it will contain. If you want 9 values you do int a[9]. However, when getting a certain value from the array, you use it's ordered element number. For example, if I have an array a[9] = {1,2,3,4,5,6,7,8,9} and I want to get the number 8, I use it's element number to identify him. So, starting the count from 1 = Element 0, 2 = Element 1, etc until 8 = Element 7. Hope that clears it up for you.
24th Sep 2016, 12:15 PM
KillZoneZ
KillZoneZ - avatar