Help with malloc(): datum ** and [i][j]

Jack Jansen jack at vu44.UUCP
Tue Aug 28 16:35:47 AEST 1984


Chris Torek:
> Think of it this way:  suppose the array is declared as
> 
> 	int a[20][50];
> 
> Suppose we're asked to fetch a[6][4]. ....
> 
> The other way we could do it is multiply the 4 times the 50 and add
> 6; that is, start with the second subscript and multiply it by the
> second subscript size, then add the first subscript.  From here we
> do the same thing as before.  So add 206 to ``a'' and fetch from there.
> If I haven't got them reversed this is ``column major'' order.
Sorry Chris, but I think this is wrong. What you should do is
multiply the second subscript by the *first* subscript size, 
and add the first subscript, or, in this example use 4*20+6, or 86.

	Jack Jansen, {philabs|decvax}!mcvax!vu44!jack



More information about the Comp.lang.c mailing list