I'm working with linked lists in C. Can someone please explain the function and purpose of:
t->next;
and
t.next;
I'm working with linked lists in C. Can someone please explain the function and purpose of:
t->next;
and
t.next;
To access the member of the struct or union the . is used. To dereference pointer to the struct or union and access the member -> is used as in he examples blelow
struct node
{
    struct node *next;
};
void foo()
{
    struct node n;
    struct node *np = &n;
     
    // accessing member of the struct 
    n.next = &n;
    // accessing member of the struct via the pointer
    np -> next = &n;
    // accessing member of the struct via the derefenced pointer
    (*np).next = &n;
    (&n) -> next = &n;
}
