Thread overview
weird bug - 2 dimensional array
Jun 16, 2003
Greg Bowen
Jun 16, 2003
Jan Knepper
Jun 16, 2003
roland
June 16, 2003
Not sure what to think of this - any help is greatly appreciated

I have a 2-dimensional array

a[9][50]

if I change a[0][50], a[1][0] gets affected??

any ideas?


June 16, 2003
Greg Bowen wrote:

> Not sure what to think of this - any help is greatly appreciated
>
> I have a 2-dimensional array
>
> a[9][50]
>
> if I change a[0][50], a[1][0] gets affected??
>
> any ideas?

Perfectly normal... a [ 0] [ 49 ] is the last element in [ 0 ].
a [ 0 ][ 50 ] will return a [ 1 ][ 0 ].
a [ 0 ][ 51 ] will return a [ 1 ][ 1 ].

etc.



--
ManiaC++
Jan Knepper


June 16, 2003
Greg Bowen a écrit :
> Not sure what to think of this - any help is greatly appreciated
> 
> I have a 2-dimensional array
> 
> a[9][50]
> 
> if I change a[0][50], a[1][0] gets affected??
> 
> any ideas?
> 
> 

in C arrays are 0 based.

int int_array[1];

the first and last element is int_array[0].
DM C++ organize arrays in memory line by line.
that means past the first line there is the beginning of the second
one (if exists ..)
IMO it is not nice programing to do that exept if you really know what you are doing and put plenty of comments this part of code ..

good luck

roland