C question -- pointer to array of characters
Walter Rowe
rowe at cme.nist.gov
Thu Oct 19 01:50:41 AEST 1989
>>>> On 17 Oct 89 22:37:59 GMT, kunkee at ficc.uu.net (randy kunkee XNX MGR) said:
kunkee> main()
kunkee> {
kunkee> char (*foo)[];
kunkee> char bar[20];
kunkee>
kunkee> foo = bar;
kunkee> }
(1) `bar' is an array of characters
(2) `foo' is a pointer to an array of characters, meaning that it's
supposed to hold the array's address. So, `foo' should hold the
address of `bar'.
(3) The value of `bar' is the address of the first character in the
array. The value of `&bar' is the address of the array `bar'.
The proper assignment, as you already know from other postings, is;
foo = &bar;
Now `foo' contains the address of the array `bar'.
The compiler was right to complain about this since you weren't using
`foo' in the manner that you declared it. Others made that point
clear, however, no one explained the reason why. This is not a flame,
just trying to help you understand how things are interpreted.
Walter
--
This is just my opinion ...
More information about the Comp.lang.c
mailing list