Поля и свойства

Структуры (записи)

typedef struct {
    //Fields
    int x, y;
    char name[16];
    //a bit field takes only one bit
    bool visible : 1;
} ColorPoint;

//C has no properties: a function checks the value before it sets the field
void setX(ColorPoint *p, int x) {
    p->x = x < 0 ? 0 : x;
}

ColorPoint point = {1, 2, "start", true};
point.y = 5;
setX(&point, -3);
//point.x is 0
//point.y is 5
//point.name is "start"
//point.visible is true

printf("point.x is %d\n", point.x);
printf("point.y is %d\n", point.y);
printf("point.name is %s\n", point.name);
printf("point.visible is %s\n", point.visible ? "true" : "false");