eolas/zk/Structs_in_C.md
2026-01-12 18:12:53 +00:00

512 B

tags
C

A struct is a custom, user-defined type, in constrast to the primitive types (int, char, float etc). They are known as compound types.

Usage

Define the custom type:

struct Person {
    int age;
    float height;
}

Then to apply the type to a variable:

struct Person thomas

And define the sub-properties:

thomas.age = 37
thomas.height = 5.8

Alternatively do all together:

struct Person thomas = {
    .age = 37,
    .height = 5.8
}