How do you declare a pointer to a two dimensional array?
Avery Colter
avery at netcom.UUCP
Sun Nov 11 09:13:01 AEST 1990
Well, any array, when referred to by name only without subscripts,
translates into a pointer to the lowest element of the array, i.e.
the location of spam[0][0].
However, at least on my machine, pointers don't take kindly to more
than one dimension of indexing.
So I resorted to making a separate array of pointers, and setting
each of the elements of this array of pointers to match the addresses
of each of the subarrays of the original.
Kinda like:
int spam [10][10];
int *pointer[10];
int index;
for (index=0;index<10;++index)
pointer[index]=spam[index];
--
Avery Ray Colter {apple|claris}!netcom!avery {decwrl|mips|sgi}!btr!elfcat
(415) 839-4567 "Fat and steel: two mortal enemies locked in deadly combat."
- "The Bending of the Bars", A. R. Colter
More information about the Comp.lang.c
mailing list