
simple array question
I don't know how to put this in a form of a question but for example, doesn't a sample array initiation "int array[4];" hold 5 elements because the elements start from array[0]?
so the array broken down would be:
array[0] , array[1] , array[2] , array[3] , array[4], right?
if so, then why do I get a page fault error from this code?
any help is appreciated.
[code]
#include<iostream.h>
int main(void)
{
int array[4];
for(int x=0; x<=4; x++)
{
array[x] = x;
}
return 0;
}
[\code]

no, the number you put in the declaration is the number of elements, not the index of the highest element.
In other words, int ar[4]; gives 4 elements from ar[0]to ar[3].
Ciao Al:o

Heh. It was answered.
int array [5];
means you can have
array[0, 1, 2, 3, 4] and nothing more.
So, if the size of the array is n, the max storage place is n1 and the array's first storage place is 0.