Teaching const
News system
news at ism780c.UUCP
Fri Apr 15 13:06:48 AEST 1988
In article <786 at srs.UUCP> srs!craig at cs.rochester.edu (Craig Schmackpfeffer) writes:
>In article <9683 at ism780c.UUCP> marv at ism780.UUCP (Marvin Rubenstein) writes:
>>In article <27071 at amdahl.uts.amdahl.com> nw at amdahl.uts.amdahl.com (Neal Weidenhofer) writes:
>>> 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?
>>
>
>Of course there is a difference! The "int * const a" declaration declares
>a pointer to an int. The "int a[1]" declaration ALLOCATES space for an
>int and "a" itself is not a pointer, but actually the location of the array.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But "a" itself a pointer or else *a would not be allowed. Nor would:
char p = a;
I wrote the >> article. I should have used a smiley. I was discussing the
*teaching* problem. Have you ever tried to explain to a novice why:
char *p; and char p[1];
mean the same when p is a parameter, but do mean the same when p is not
a parameter. Or why:
extern char p[];
makes sense, but
char p[];
is an error. If your students don't have any problems with this then they
are much smarter than mine (smiley used this time :-).
Marv Rubinstein -- Interactive Systems
More information about the Comp.lang.c
mailing list