结构体的不同形式

单片机

1. 包含指针成员的结构体

typedef struct {
    int id;
    char *name;
    float *scores;
} Student;

2. 嵌套结构体

typedef struct {
    float x;
    float y;
} Point;

typedef struct {
    Point start;
    Point end;
} Line;

3. 带有位字段的结构体

typedef struct {
    unsigned int red : 3;
    unsigned int green : 3;
    unsigned int blue : 2;
} Color;

4. 含有数组成员的结构体

typedef struct {
    int id;
    char name[50];
    float scores[5];
} Student;

5. 包含函数指针成员的结构体

typedef struct {
    void (*draw)(void);
    void (*move)(int x, int y);
} Shape;

6. 使用匿名结构体

typedef struct {
    int x;
    int y;
} Point;

typedef struct {
    Point start;
    Point end;
} Line;

这些是结构体在C语言中的一些不同形式的例子,展示了结构体的灵活性和多样性。