Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #24673

Re: dereference

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: dereference
Date 2012-08-20 18:46 -0700
Organization None to speak of
Message-ID <lnobm5hva8.fsf@nuthaus.mib.org> (permalink)
References <k0uc8k$9s4$1@speranza.aioe.org> <lnwr0ti4cw.fsf@nuthaus.mib.org> <k0un32$iv$1@speranza.aioe.org>

Show all headers | View raw


"Bill Cunningham" <nospam@nspam.invalid> writes:
> Keith Thompson wrote:
>> No, you clearly don't have dereferencing down now.
>>
>>> #include <stdio.h>
>>>
>>> int main(void)
>>> {
>>>     int x;
>>>     x = 2;
>>>     int *px = &x;
>>>     printf("%d\n", px);
>>
>> The problem here is that you're not dereferencing px.  Change `px` to
>> `*px` and it will work.
>
>     So when printing a pointer it should always be derefenced then. I missed 
> that. What I've been reading about dereferencing this that the pointer 
> changes the value of the pointee.

To "dereference" a pointer is to access the object that it points to.

If you want to print a pointer value, use "%p" and cast the pointer
value to void*.  (That's probably not what you want to do here.)

If you want to print the value of the object that the pointer points to,
you need to dereference it, using the unary "*" operator.

This would have been less annoying if you hadn't claimed to understand
dereferencing.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-20 18:04 -0400
  Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-20 15:30 -0700
    Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-20 18:37 -0400
      Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-20 18:43 -0700
      Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-22 14:42 -0400
        Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-22 12:10 -0700
          Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-22 17:38 -0400
    Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-20 21:09 -0400
      Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-20 18:46 -0700
        Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-21 16:15 -0400
        Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-21 16:26 -0400
      Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-22 14:49 -0400
        Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-22 18:10 -0400
          Re: dereference Barry Schwarz <schwarzb@dqel.com> - 2012-08-22 17:36 -0700
            Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-22 20:50 -0400
              Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-22 17:54 -0700
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-22 21:23 -0400
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-22 21:26 -0400
                Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-23 12:55 -0400
                Re: dereference Mark Bluemel <mark_bluemel@pobox.com> - 2012-08-24 08:05 +0100
                Re: dereference Hans Vlems <hvlems@freenet.de> - 2012-08-24 03:00 -0700
                Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-24 13:31 -0400
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-24 17:20 -0400
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-24 19:36 -0400
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-24 20:42 -0700
                Re: dereference Hans Vlems <hvlems@freenet.de> - 2012-08-27 00:11 -0700
                Re: dereference Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-27 02:01 -0700
                Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-27 03:24 -0700
                Re: dereference Barry Schwarz <schwarzb@dqel.com> - 2012-08-24 21:44 -0700
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-25 09:46 -0400
                Re: dereference Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2012-08-25 16:22 +0200
                Re: dereference Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2012-08-25 16:33 +0200
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-25 08:07 -0700
                Re: dereference Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2012-08-25 17:55 +0200
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-25 10:58 -0700
                Re: dereference Ike Naar <ike@iceland.freeshell.org> - 2012-08-25 20:39 +0000
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-26 14:49 -0700
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-25 18:36 -0400
                Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-25 16:42 -0700
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-25 20:19 -0400
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-26 14:40 -0700
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-26 14:46 -0700
                Re: dereference Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-27 02:11 -0700
                Re: dereference James Kuyper <jameskuyper@verizon.net> - 2012-08-27 08:36 -0400
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-27 10:38 -0700
                Re: dereference James Kuyper <jameskuyper@verizon.net> - 2012-08-27 13:55 -0400
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-27 12:57 -0700
                Re: dereference James Kuyper <jameskuyper@verizon.net> - 2012-08-27 16:25 -0400
                Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-29 10:41 -0400
                Re: dereference Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-27 02:09 -0700
                Re: dereference Barry Schwarz <schwarzb@dqel.com> - 2012-08-25 12:16 -0700
                Re: dereference Keith Thompson <kst-u@mib.org> - 2012-08-25 16:40 -0700
                Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-25 21:21 -0400
                Re: dereference Barry Schwarz <schwarzb@dqel.com> - 2012-08-25 21:48 -0700
                Re: dereference Les Cargill <lcargill99@comcast.com> - 2012-08-25 13:08 -0500
                Re: dereference Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-27 02:02 -0700
                Re: dereference Andrew Cooper <amc96@cam.ac.uk> - 2012-08-25 02:53 +0100
                Re: dereference Hans Vlems <hvlems@freenet.de> - 2012-08-27 00:10 -0700
                Re: dereference Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-27 02:14 -0700
                Re: dereference Adrian Ratnapala <adrian.ratnapala@gmail.com> - 2012-08-27 10:34 -0700
                Re: dereference Kenneth Brody <kenbrody@spamcop.net> - 2012-08-29 10:22 -0400
  Re: dereference Les Cargill <lcargill99@comcast.com> - 2012-08-20 17:38 -0500
    Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-20 18:41 -0400
  Re: dereference "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-08-20 16:43 -0700
    Re: dereference Mark Bluemel <mark_bluemel@pobox.com> - 2012-08-21 09:22 +0100
    Re: dereference "Bill Cunningham" <nospam@nspam.invalid> - 2012-08-21 16:12 -0400

csiph-web