Question about pointers

Discussion in 'C++' started by JS, Mar 15, 2005.

  1. JS

    JS Guest

    I have the following:

    int x = 2;

    int *ip;

    ip = &x;


    now as I understand *ip equals 2.


    Is it possible to say that *ip equals a value and & is the adress for that
    value?

    JS
     
    JS, Mar 15, 2005
    #1
    1. Advertising

  2. JS wrote:

    > I have the following:
    >
    > int x = 2;
    >
    > int *ip;
    >
    > ip = &x;
    >
    >
    > now as I understand *ip equals 2.
    >
    >
    > Is it possible to say that *ip equals a value and & is the adress for that
    > value?



    ip is a variable that stores the memory address of variable x.

    When you dereference ip like this: *ip, you access x.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Mar 15, 2005
    #2
    1. Advertising

  3. JS wrote:
    > I have the following:
    >
    > int x = 2;
    >
    > int *ip;
    >
    > ip = &x;
    >
    >
    > now as I understand *ip equals 2.
    >
    >
    > Is it possible to say that *ip equals a value and & is the adress for that
    > value?


    '&' is an operator. It is not an address of anything. Was it a typo?

    Anyway... *ip designates an object. The original name of that object is
    'x'. The value of 'x' and, consequently, of *ip, is 2, since they both
    designate the same object.

    V
     
    Victor Bazarov, Mar 15, 2005
    #3
  4. JS

    JS Guest

    "Ioannis Vranos" <> skrev i en meddelelse
    news:1110923535.5379@athnrd02...
    > JS wrote:
    >
    > > I have the following:
    > >
    > > int x = 2;
    > >
    > > int *ip;
    > >
    > > ip = &x;
    > >
    > >
    > > now as I understand *ip equals 2.
    > >
    > >
    > > Is it possible to say that *ip equals a value and & is the adress for

    that
    > > value?

    >
    >
    > ip is a variable that stores the memory address of variable x.
    >
    > When you dereference ip like this: *ip, you access x.


    ok so the value of x and *ip is both 2 if int x = 2 right?
     
    JS, Mar 15, 2005
    #4
  5. Ioannis Vranos, Mar 15, 2005
    #5
  6. JS

    codigo Guest

    > ok so the value of x and *ip is both 2 if int x = 2 right?
    >
    >


    A clear distinction needs to be made here. The two variables are one and the
    same entity. It matters not which is modified or initialized. The correct
    statement would be that *ip is x, regardless of what value it happens to
    hold.
     
    codigo, Mar 16, 2005
    #6
  7. codigo wrote:

    > A clear distinction needs to be made here. The two variables are one and the
    > same entity. It matters not which is modified or initialized. The correct
    > statement would be that *ip is x, regardless of what value it happens to
    > hold.



    ip and x are *two* different objects with a separate memory address each
    one. ip is an int pointer variable, that is, it stores memory addresses
    of int variables, while x is an int variable.



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Mar 16, 2005
    #7
  8. JS

    Guest

    Yes, but *ip -- the location ip points to -- is indistinguishable from
    x, at least as far as I can tell.
     
    , Mar 16, 2005
    #8
  9. wrote:

    > Yes, but *ip -- the location ip points to -- is indistinguishable from
    > x, at least as far as I can tell.



    ip dereferenced, accesses x. We use very accurate terminology in clc++. :)



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Mar 16, 2005
    #9
  10. JS

    Howard Guest

    <> wrote in message
    news:...
    > Yes, but *ip -- the location ip points to -- is indistinguishable from
    > x, at least as far as I can tell.
    >


    That is, so long as ip isn't changed to point elsewhere!

    -Howard
     
    Howard, Mar 16, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil
    Replies:
    1
    Views:
    650
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    767
    Ron Natalie
    Sep 18, 2003
  3. A
    Replies:
    3
    Views:
    459
    Alan Kelon
    Oct 29, 2003
  4. Chad

    pointers to pointers question

    Chad, Mar 26, 2006, in forum: C Programming
    Replies:
    5
    Views:
    316
    Default User
    Mar 27, 2006
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    683
Loading...

Share This Page