*tst-> or (*tst)?

This is a discussion on *tst-> or (*tst)? within the C Programming forums, part of the General Programming Boards category; I started to learn about structures, yes, I know it's an important part of the C language, now I have ...

  1. #1
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    *tst-> or (*tst)?

    I started to learn about structures, yes, I know it's an important part of the C language, now I have a question.

    In my book sometimes he uses:
    Code:
    (*prd).name
    And sometimes he uses:
    Code:
    *prd->name
    Is there any difference? if yes, when and why should I use -> or (*prd)? And if you can, please write here, the way you write.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    The arrow operator is syntactic sugar, both methods do the same thing, but -> is easier to type.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Ok, so both methods make's same thing, that's what I wanted to know, thanks prelude.

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Prelude
    The arrow operator is syntactic sugar, both methods do the same thing, but -> is easier to type.

    -Prelude
    Actually, look at that again. I don't mean to correct you, but here he actually IS doing 2 different things.

    The first one accesses the member of the object being pointed to while the second accesses the member of the object being pointed to and then dereferences it.

    Unless he mistyped.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Actually, look at that again.
    You're correct, I see this question so much I don't even read the code anymore. Though I believe it likely was a typo.

    >I don't mean to correct you
    If I make a mistake then by all means, inform me of it.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 01:12 PM
  2. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 08:48 AM
  3. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM
  4. electricity > AC circuits > tesla coil
    By dbaryl in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 03-14-2002, 02:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21