C'mon, guys! (Really, pointer pedagogy)

Pete Zakel pete at valid.UUCP
Thu Jul 3 13:52:39 AEST 1986


> Just a quick remark.  When I was learning C, I understood that "*pi" meant "the
> contents of pi," but somehow had difficulty conceptualizing why the declaration
> "int *pi;" declares pi as a pointer to an int;  that is, I knew it was a
> convention I had to memorize, but it didn't seem mnemonic to me.  Then, about
> a month ago, revelation!:  read this as "the contents of pi is an integer;"
> which implies, "pi is that which contains (or points to)" an integer.  Somehow 
> it made thinking about the declarations easier.  It's occurred to me that maybe
> everyone else in the world sees this from day 1, but for us dumb folks, having
> this reading pointed out would probably make the learning process easier....
> 
> Peter S. Shenkin

I find it a lot easier to think of "int i" as "i is an integer", "int *pi" as
"pi is a pointer to an integer", "pi" as "the address of an integer", and
"*pi" as "the integer that pi points to".  Of course, being an assembly
programmer at heart, I tend to understand the things in the way that they
are actually used by the machine.  If one thinks of "pi" as the name of a
box, then the contents of that box is the address of an integer, NOT the
integer itself.  I would think of "*pi" as the box that resides at the
address contained in "pi", which contains an integer.

In the wording used above, I would think using "the contents of what pi
points to" as a definition for "*pi" would be much better than what is 
stated above.
-- 
-Pete Zakel (..!{hplabs,amd,pyramid,ihnp4}!pesnta!valid!pete)



More information about the Comp.lang.c mailing list