Search code examples
cpointersoperatorsdereference

C - how do I read * and -> together?


If I have :

char *name; //this is in a struct

*row->name //row is able to get in the struct

How do I read *row->name and what is it returning?

I'll link the code I am reading: http://pastebin.com/MvLXkDCz


Solution

  • First the -> operator is evaluated and then the resulting pointer which is pointing to what name points to is dereferenced with *. So it's the same as

    row->name[0]
    

    and IMHO this is a better way of expressing the same (althought sometimes using the indirection operator * is clearer).