Values & References8 / 18
Up next

Struct through a pointer

#include <stdio.h>

typedef struct {
    int x;
    int y;
} Point;

void move(Point *p, int dx, int dy) {
    p->x += dx;
    p->y += dy;
}

int main(void) {
    Point p = {.x = 1, .y = 1};
    move(&p, 2, 3);
    printf("(%d, %d)\n", p.x, p.y);
    return 0;
}
What you're solving

-> dereferences and selects a field