The "->" operator

Discussion in 'C Programming' started by Jeff Rodriguez, Dec 12, 2003.

  1. What does this do? I've been looking online and I've seen mention that it exists
    as well as examples to it's use but still no explination as to exactly what it does.

    TFTH,
    Jeff
     
    Jeff Rodriguez, Dec 12, 2003
    #1
    1. Advertising

  2. Jeff Rodriguez

    Ben Pfaff Guest

    Jeff Rodriguez <> writes:

    > What does this do? I've been looking online and I've seen mention that
    > it exists as well as examples to it's use but still no explination as
    > to exactly what it does.


    The -> operator dereferences its left operand, then accesses one
    of the members of the referenced object (which must be of
    structure or union type). a->b is equivalent to (*a).b. The ->
    operator is simply there to reduce the need for parentheses in
    accessing a structure member through a pointer.
    --
    Here's a tip: null pointers don't have to be *dull* pointers!
     
    Ben Pfaff, Dec 12, 2003
    #2
    1. Advertising

  3. Jeff Rodriguez

    Les Cargill Guest

    Jeff Rodriguez wrote:
    >
    > What does this do? I've been looking online and I've seen mention that it exists
    > as well as examples to it's use but still no explination as to exactly what it does.
    >
    > TFTH,
    > Jeff


    It's a struct dereference by pointer.

    struct V a;
    struct V *b;

    b = &a;

    a.<something> and b-><something> are now exactly the same thing.

    --
    Les Cargill
     
    Les Cargill, Dec 12, 2003
    #3
  4. Les Cargill wrote:

    > Jeff Rodriguez wrote:
    >
    >>What does this do? I've been looking online and I've seen mention that it exists
    >>as well as examples to it's use but still no explination as to exactly what it does.
    >>
    >>TFTH,
    >>Jeff

    >
    >
    > It's a struct dereference by pointer.
    >
    > struct V a;
    > struct V *b;
    >
    > b = &a;
    >
    > a.<something> and b-><something> are now exactly the same thing.
    >
    > --
    > Les Cargill

    Easy enough!

    Thank you much.

    Jeff
     
    Jeff Rodriguez, Dec 12, 2003
    #4
  5. Jeff Rodriguez

    Lew Pitcher Guest

    Jeff Rodriguez wrote:

    > What does this do? I've been looking online and I've seen mention that
    > it exists as well as examples to it's use but still no explination as to
    > exactly what it does.


    The -> operator is a structure element pointer dereference operator. It
    takes a pointer to a structure on the left and a membername on the right,
    and results in the value of the member of the structure as pointed to by the
    pointer.

    In other words, assuming something defined like

    struct { int number } *pointer;

    then

    pointer->number

    is a shortform for

    (*pointer).number

    That's it.

    --
    Lew Pitcher, IT Consultant, Application Architecture
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
     
    Lew Pitcher, Dec 12, 2003
    #5
  6. Jeff Rodriguez

    Dan Pop Guest

    In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <> writes:

    >What does this do? I've been looking online and I've seen mention that it exists
    >as well as examples to it's use but still no explination as to exactly what it does.


    What does your favourite C book say about it?

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Dec 12, 2003
    #6
  7. Jeff Rodriguez

    I.M.A Troll Guest

    Dan Pop wrote:
    > In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <> writes:
    >
    >
    >>What does this do? I've been looking online and I've seen mention that it exists
    >>as well as examples to it's use but still no explination as to exactly what it does.

    >
    >
    > What does your favourite C book say about it?
    >
    > Dan


    Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
    example of the prior respondents and answer the question in a serious
    and congenial manner (or refrain from making any reply if the question
    has already been answered)? Expertise does not excuse bad manners.
     
    I.M.A Troll, Dec 14, 2003
    #7
  8. Jeff Rodriguez

    John Bode Guest

    "I.M.A Troll" <> wrote in message news:<>...
    > Dan Pop wrote:
    > > In <ilcCb.2069$J77.331@fed1read07> Jeff Rodriguez <> writes:
    > >
    > >
    > >>What does this do? I've been looking online and I've seen mention that it exists
    > >>as well as examples to it's use but still no explination as to exactly what it does.

    > >
    > >
    > > What does your favourite C book say about it?
    > >
    > > Dan

    >
    > Dan, it wasn't necessary to lapse into sarcasm. Why not just follow the
    > example of the prior respondents and answer the question in a serious
    > and congenial manner (or refrain from making any reply if the question
    > has already been answered)? Expertise does not excuse bad manners.


    This could be a sign I've been hanging around c.l.c. too long, but
    Dan's answer is perfectly appropriate (if a bit brusque, but that's
    part of Dan's charm). Answers to basic questions such as this are
    best found in your handy C reference manual, not in an online
    newsgroup where there is some delay in getting an answer, and where at
    least one of the answers you get will be wrong or useless.

    The OP needs to get into the habit of checking his C reference manual
    *first*; if he has additional questions, he needs to check out the
    FAQ; and then, if he still needs guidance, ask a question here.
     
    John Bode, Dec 15, 2003
    #8
    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. Jakob Bieling

    Q: operator void* or operator bool?

    Jakob Bieling, Mar 5, 2004, in forum: C++
    Replies:
    2
    Views:
    597
    Rob Williscroft
    Mar 5, 2004
  2. John Smith
    Replies:
    2
    Views:
    434
    Ivan Vecerina
    Oct 6, 2004
  3. Alex Vinokur
    Replies:
    4
    Views:
    3,064
    Peter Koch Larsen
    Nov 26, 2004
  4. Alex Vinokur
    Replies:
    3
    Views:
    5,044
    Jeff Schwab
    Mar 20, 2005
  5. Tim Clacy
    Replies:
    15
    Views:
    2,713
    Kanenas
    May 30, 2005
Loading...

Share This Page