Path: utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpcupt1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.lang.c Subject: Re: Re: Teaching const: decoding declarations Message-ID: <2550063@hpisod2.HP.COM> Date: 10 Apr 88 05:54:40 GMT References: <10203@steinmetz.steinmetz.ge.com> Organization: Hewlett Packard, Cupertino Lines: 30 > > int * const a; > >decodes as: > > a is a constant, > > a is a constant pointer, > > a is a constant pointer to an int. > > (i.e., a cannot be modified but *a can.) > > Note that: > int a[1]; > decodes as: > a is a constant, > a is a constant pointer, > a is a constant pointer to an int. > (i.e., a cannot be modified but *a can.) > > But there must (?) be some difference between the two. How do you teach > this? The first declaration requests space for a pointer to an integer. If this is a static declaration, the value is initialized to 0, so a can never point to an object, and *a cannot be used to store a value. Otherwise, the (automatic) variable gets a garbage initial value which cannot be set to anything useful. The second declaration requests space for an array of one integer (except when used to declare a formal parameter) and *a can immediately be used to store an integer. Dave Decot hpda!decot