Results 1 to 3 of 3

Thread: what does -> mean in C?

  1. #1
    Join Date
    Nov 2006
    Beans
    236
    Distro
    Ubuntu 10.04 Lucid Lynx

    Question what does -> mean in C?

    Hi just looking through some tutorials and came across this symbol:

    Code:
    ->
    just wondering what it means, thanks.

  2. #2
    Join Date
    Jul 2005
    Location
    2 exits past crazy
    Beans
    4,223
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: what does -> mean in C?

    It is used when you have a pointer to a structure and you want to dereference one of the stuct's fields.

    Code:
    typedef struct
    {
    char a;
    int b;
    } mystruct;
    
    mystruct example;
    mystruct *ptr;
    
    ptr = &example;
    
    ptr->a = 'A';
    ptr->b = 1;
    
    (*ptr).a = 'B';
    (*ptr).b = 2;

  3. #3
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: what does -> mean in C?

    In case it isn't clear from yabbadabbadont's post, the
    "->" syntax is syntactic sugar for "(*ptr)." .
    Code:
    ptr->
    (*ptr).
    are equivalent, where the former was introduced strictly for convenience.
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •