pointers to arrays
Kenneth R. Ballou
ballou at brahms
Wed Nov 19 18:50:21 AEST 1986
In article <273 at bms-at.UUCP> stuart at bms-at.UUCP (Stuart D. Gathman) writes:
>I am still confused about several things concerning pointers to arrays.
>
>There does seem to be such a type, even in K & R.
>
>1) How does one get such an animal? The only methods I can figure are
>
> a) a cast: ( type (*)[] ) array_of_type
Also, you could have:
int (* foo) [10];
foo = (int (*) [10]) malloc (4 * sizeof (int [10]))
Then, * foo, * (foo + 1), * (foo + 2), and * (foo + 3) would each have type
"array of 10 ints."
> b) a function returning such a type (but the return must use a cast!)
No, this function could now say return foo + 2;
>3) It seems to me that any distinction between a pointer to an array
> and a pointer to its first element is purely semantic.
Nope, it affects address arithmetic.
--------
Kenneth R. Ballou ...!ucbvax!brahms!ballou
Department of Mathematics ballou at brahms.berkeley.edu
University of California
Berkeley, California 94720
More information about the Comp.lang.c
mailing list