Why char *f is different from char f[]
utzoo!decvax!ucbvax!unix-wizards
utzoo!decvax!ucbvax!unix-wizards
Fri Dec 11 08:14:23 AEST 1981
>From harpo!jerry at Berkeley Fri Dec 11 08:07:17 1981
There is a difference between a pointer to a character
and an array of characters, although in some contexts
C tries to hide that fact. The declaration "char *ptr"
says that the variable ptr contains a pointer to a character.
Normally, the declaration "char ary[]" says that ary contains
an array of characters. But in most contexts C interprets
occurances of "ary" as equivalent a pointer to the first character
of the array. If in another file you declare "char *ary",
the value of ary will be the first few characters of ary,
interpreted as a pointer.
The real confusion comes when C comes to interpreting
function declarations like "foo(ary) char ary[]". In
that case C interprets "ary" as a pointer to a character.
I think that the semantics of arrays is one of the worst
thought out features of C.
More information about the Comp.unix.wizards
mailing list