Quiz Entry - updated: 2026.07.10
What's the difference between -> and . for struct access?
Use . when you hold the struct itself (p.x) and -> when you hold a pointer to it (ptr->x); ptr->x is just shorthand for (*ptr).x.
struct point { int x, y; };
struct point p = {10, 20};
struct point *ptr = &p;
// Direct access (variable)
p.x = 5;
// Pointer access
// Preferred
ptr->x = 5;
// Equivalent but uglier
(*ptr).x = 5;
Why -> exists:
*ptr.xdoesn't work because.has higher precedence than**ptr.xis parsed as*(ptr.x)which is wrong(*ptr).xworks but is clunkyptr->xis shorthand for(*ptr).x
Chaining:
struct node {
int value;
struct node *next;
};
// Follow chain of pointers
node->next->next->value
// Equivalent to: (*((*node).next)).next)->value // Yuck!