Home › C Tutorial › Structs and pointers
Structs and pointers
Use -> on struct pointers.
Pass struct pointers to avoid copying. p->x equals (*p).x.
Example code
#include <stdio.h>
struct Pt { int x, y; };
void move(struct Pt *p) { p->x += 10; }
int main() {
struct Pt a = {1, 2};
move(&a);
printf("%d %d\n", a.x, a.y);
return 0;
}