Struct Pointers & Nesting in C
Large structs travel by pointer: f(&p) passes an address instead of copying the whole value, and inside, p->x is shorthand for (*p).x. The arrow operator is C's most-read piece of punctuation — struct access through pointers, everywhere from linked lists to file handles (FILE *fp is exactly this).
Structs nest freely (a struct holding another struct, or pointers to its own type for linked structures), and arrays of structs lay records out contiguously for cache-friendly iteration. Const struct pointers (const Point *p) promise read-only traversal.
Arrow for pointer access
p->x means (*p).x — member access through a pointer in one readable operator.
Pass big structs by pointer
void f(const struct Big *b) avoids copying megabytes per call while forbidding modification.
Nest and self-reference
Structs contain structs (Line has two Points) and pointers to their own type (Node { ...; Node *next; }) — the linked-structure foundation.
Arrays of structs
struct Rec table[100]; lays records contiguously — iterate with table[i].field for cache-friendly scans.
#include <stdio.h> typedef struct { int x; int y;} Point; void move(Point *p, int dx) { p->x += dx; } int main(void) { Point p = {1, 2}; move(&p, 10); printf("%d,%d\n", p.x, p.y); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.