www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - weird bug - 2 dimensional array

reply "Greg Bowen" <mail gregbowen.com> writes:
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?
Jun 16 2003
next sibling parent Jan Knepper <jan smartsoft.us> writes:
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
Jun 16 2003
prev sibling parent roland <--nancyetroland free.fr> writes:
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
Jun 16 2003