Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ames!lll-tis!lll-lcc!ptsfa!laticorp!sarah From: sarah@laticorp.UUCP (Sarah Groves Hobart) Newsgroups: comp.unix.wizards Subject: Re: have I found a bug in K&R? Message-ID: <324@laticorp.UUCP> Date: Tue, 13-Oct-87 15:17:55 EDT Article-I.D.: laticorp.324 Posted: Tue Oct 13 15:17:55 1987 Date-Received: Fri, 16-Oct-87 01:34:59 EDT References: <517@hubcap.UUCP> <321@laticorp.UUCP> <7608@steinmetz.steinmetz.UUCP> Organization: LatiCorp, Inc., San Francisco Lines: 34 Keywords: argv definition In article <7608@steinmetz.steinmetz.UUCP>, stpeters@dawn.steinmetz (Dick St.Peters) writes: > In article <321@laticorp.UUCP> sarah@laticorp.UUCP (Sarah Groves Hobart) writes: > >Remember that the following declarations are equivalent: > > > >char s[]; > > > >char *s; > > Actually, they're not. The difference is like that between a constant > and a variable: you can change the value of s (the address it points > to) if you declare it as a pointer [variable], but you can't if you > declare it as an array [constant]. Consider what "&s" means in the > two cases. > > > Right. An array name IS a constant, so something like: ptr = &array_name; is illegal. I was referring to their equivalence as formal parameters in a function definition. A function that has been passed an array name can believe it has either an array or a pointer and work with it accordingly. It is, however, legal to pass a function something of the form &a[0], or even &a[5]. This is useful if you only want to pass part of a larger array. Interested parties are referred to K&R pp. 94-96. Sarah Groves Hobart {ihnp4,amdahl,sun}!ptsfa!laticorp!sarah