Methods

Structures (records)

//C has no methods: a function takes a pointer to the struct first
typedef struct {
    int x, y;
} Point;

//const: the function only reads the point
void pointToString(const Point *p, char *buffer, size_t size) {
    snprintf(buffer, size, "x = %d; y = %d", p->x, p->y);
}

void pointMove(Point *p, int right, int down) {
    p->x += right;
    p->y += down;
}

Point p1 = {1, 2};
char str1[32];
pointToString(&p1, str1, sizeof str1);
//str1 is "x = 1; y = 2"

pointMove(&p1, 5, -1);
char str2[32];
pointToString(&p1, str2, sizeof str2);
//str2 is "x = 6; y = 1"

printf("str1 is %s\n", str1);
printf("str2 is %s\n", str2);