pointers to arrays
Guy Harris
guy at auspex.UUCP
Sat Feb 18 19:37:36 AEST 1989
>Pointers are usually used to modify things, and &E I believe would
>be used to modify the address of the array since that's what E
>is (the address of the array).
You may believe that, but you're wrong; in the language described by the
pANS, "E" is not the address of the array, "E" is the array itself.
(This may be an oversimplification, but I think it gets the essential
point.) In most contexts an array-valued expression is converted to an
expression that points to the first element of the array, but "operand
of 'sizeof'" and "operand of unary &" are contexts where it isn't
converted.
Pointers are usually used to modify things, and you can definitely
modify an array by assigning to elements of that array:
int (*foo)[13];
int bar[13];
foo = &bar;
(*foo)[7] = 666;
should work in an ANSI C program once ANSI C exists and programs can be
written in it and compiled by ANSI C-conformant compilers.
More information about the Comp.lang.c
mailing list