Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!topaz!nike!ucbcad!ucbvax!decvax!mcnc!ncsu!uvacs!edison!jso From: jso@edison.UUCP (John Owens) Newsgroups: net.lang.c,net.micro.pc,net.unix Subject: Re: C'mon, guys! (Really, pointer pedagogy) Message-ID: <811@edison.UUCP> Date: Thu, 26-Jun-86 14:46:36 EDT Article-I.D.: edison.811 Posted: Thu Jun 26 14:46:36 1986 Date-Received: Fri, 4-Jul-86 03:41:21 EDT References: <487@cubsvax.UUCP> Organization: General Electric Company, Charlottesville, VA Lines: 33 Xref: watmath net.lang.c:9711 net.micro.pc:8974 net.unix:8501 In article <487@cubsvax.UUCP>, peters@cubsvax.UUCP writes: > 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. > Peter S. Shenkin Columbia Univ. Biology Dept., NY, NY 10027 Maybe it's my machine-language heritage showing, but I've always found it least confusing to think of "pi" as "the contents of pi" (which is a pointer), "*pi" as "that which (the contents of) pi points to", "int i" as declaring i to contain an int, and "int *pi" as declaring pi to contain a pointer to an int. The crucial difference is in the notions of "to contain" and "to be". The trick is that "int i" does not mean that i *is* an int, but that i *is* a variable which contains an int. The expression "i" is, of course, an int: the int which i contains. As far as the syntax of the declaration goes, this has proven useful: int pi; (the expression) pi is an int int *pi; (the expression) *pi is an int int pi[2]; (the expression) pi[i] is an int int *pi(); (the expression) *pi() is an int John Owens @ General Electric Company (+1 804 978 5726) edison!jso%virginia@CSNet-Relay.ARPA [old arpa] edison!jso@virginia.EDU [w/ nameservers] jso@edison.UUCP [w/ uucp domains] {cbosgd allegra ncsu xanth}!uvacs!edison!jso [roll your own]