Aucbvax.5442
fa.unix-wizards
utzoo!decvax!ucbvax!unix-wizards
Fri Dec 11 08:14:23 1981
Why char *f is different from char f[]
>From harpo!jerry@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.

-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <[email protected]>
of http://communication.ucsd.edu/A-News/


This Usenet Oldnews Archive
article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.

2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.