How do you declare a pointer to a two dimensional array?

Doug Gwyn gwyn at smoke.brl.mil
Wed Nov 7 22:20:48 AEST 1990


In article <9197 at aggie.ucdavis.edu> rogers at iris.ucdavis.edu (Brewski Rogers) writes:
>given the array:
>	float	spam[4][4];
>How do I declare a pointer to it? Is this possible?

You don't declare a pointer to spam; however, you might declare a pointer
to an array having the same type as spam and initialize it to point to spam.
This may not work in pre-ANSI C compilers that don't allow you to take the
address of an array, in which case you can use just spam or spam[0] and cast
it to the desired type.
	float	(*spamp)[4][4] = &spam;	/* ANSI */
	float	(*spamq)[4][4] = ((*)[4][4])spam;	/* others */



More information about the Comp.lang.c mailing list