Mail Archives: djgpp/1996/04/04/01:43:00
Reply to message 8964006 from CALVID AT RPI DOT ED on 04/01/96 4:59PM
> for(i=0; i<50; i++)
> for(j=0; j<50; j++)
> array1[i][j] = 0;
>
> array2[0] = 1;
> array2[1] = 2;
> cout << array2[(array1[i][j])] << endl;
At the end of your for loops, i and j are each 50. This is out of the bounds
of array1, which is subscripted [0..49][0..49]. Remember that array
subscripts begin with zero! As a result, the value the program finds at
array1[50][50] is a random piece of garbage in your memory somewhere,
which will almost certainly cause unexpected results when used as a
subscript of array2! The reason DJGPP gives you SIGSEGV is that it is
much more particular about what areas of memory you access than is
Linux.
I you really want to initialize the array to zero on startup, why not just
declare
it static?
John
- Raw text -