Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!ut-sally!pyramid!pesnta!valid!pete From: pete@valid.UUCP (Pete Zakel) Newsgroups: net.lang.c,net.micro.pc,net.unix Subject: Re: C'mon, guys! (Really, pointer pedagogy) Message-ID: <405@valid.UUCP> Date: Wed, 2-Jul-86 23:52:39 EDT Article-I.D.: valid.405 Posted: Wed Jul 2 23:52:39 1986 Date-Received: Fri, 4-Jul-86 01:28:00 EDT References: <487@cubsvax.UUCP> Organization: Valid Logic, San Jose, CA Lines: 26 Xref: watmath net.lang.c:9710 net.micro.pc:8969 net.unix:8499 > 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)