Thread: Pointer in struct?

  1. #16
    Registered User
    Join Date
    Apr 2007
    Posts
    26
    He2 I haven't learnt the operator precedence yet

    but thanks to both of you! I've learnt two new things

    I think my problem has solved..

  2. #17
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    You might also have learned that, if you have a pointer to a struct, you can use two different ways to access its members:

    Code:
    struct myStruct{
        int number;
    };
    
    int main( void )
    {
        struct myStruct *s = malloc(sizeof(struct myStruct));
    }
    In this case, the two following operations are the same:

    Code:
    (*s).number;
    
    // or
    s->number;
    In fact, the "->" operator has been introduced to automatically dereference a pointer to a struct to immediately access its members.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer problem or so...
    By TL62 in forum C Programming
    Replies: 19
    Last Post: 01-12-2008, 11:45 PM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. "dereferencing pointer to incomplete type"
    By incognito54 in forum C Programming
    Replies: 2
    Last Post: 11-01-2005, 09:50 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM