Definition and initialization

Structures (records)

struct Point {
    int x, y;
};

//C needs the word struct before the name
struct Point p1 = {1, 2};
//p1 is (1, 2)

//the fields that are not named get zero
struct Point p2 = {.x = 5};
//p2 is (5, 0)

//{} sets every field to zero;
//without an initializer a local struct holds garbage
struct Point p3 = {};
//p3 is (0, 0)

//a struct without a name, only for this variable
struct {
    int top, left;
} p4 = {3, 4};
//p4 is (3, 4)

//typedef spares the word struct
typedef struct {
    int width, height;
} Size;

Size size = {.height = 20, .width = 10};
//size is (10, 20)

printf("p1 is (%d, %d)\n", p1.x, p1.y);
printf("p2 is (%d, %d)\n", p2.x, p2.y);
printf("p3 is (%d, %d)\n", p3.x, p3.y);
printf("p4 is (%d, %d)\n", p4.top, p4.left);
printf("size is (%d, %d)\n", size.width, size.height);