Array names as pointers

chris at mimsy.UUCP chris at mimsy.UUCP
Thu Feb 12 18:55:13 AEST 1987


In article <762 at bath63.ux63.bath.ac.uk> ma6nrr at bath63.ux63.bath.ac.uk
(Rashbrook) writes:
>I know that for a single-dimension array e.g.
>int a[20]; then a means &a[0].Is this generally
>true for multidimensional arrays

Is what generally true?  Abstracting from a single example is a
dangerous game; I cannot guess what you mean by `this'.

In almost all contexts, an object of type `array <n> of <type>' is
altered to read `pointer to <type>', the value of the pointer being
the address of the first element of that array.  For example, given

	char a[7][3];	/* array 7 of array 3 of char */

the compiler sees the following types:

	a		/* pointer to array 3 of char */
or	&a[0]		/* pointer to array 3 of char */

	a[0]		/* pointer to char */
or	&a[0][0]	/* pointer to char */

All of these expressions have the same `value' but different types;
the types could conceivably be encoded as bits in the value field
(e.g., tagged architectures) or in some other way alter the actual
values, but these all represent the same memory location.

>e.g. will
>	int b[5][6];
>	write ( fd , (char *) b , 30 * sizeof( int ) );
> 
>write out only the whole of array b to file no. fd ?

Yes.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list