C中这2个结构声明之间的区别

Difference between these 2 declarations of structures in C

我正在为大学做这个项目,他们给了我一个示例代码,供我在声明结构时使用,另一个是我如何使用 PowerPoint 和其他研究中的信息声明它 material。

这是他们给我的代码:

typedef struct sala local, *plocal;
struct sala {
    int id;
    int capacidade;
    int liga[3];
};

这是我做的另一个结构的代码:

typedef struct pessoa {
    char id[15];
    int idade;
    char estado;
    int dias;
} pessoa;

谁能给我解释一下区别?

在我的代码编辑器中 "local" 和“*local”显示为蓝色。 (我使用 Netbeans)。

这个 typedef 声明

typedef struct sala local, *local;
struct sala {
    int id;
    int capacidade;
    int liga[3];
};

无效,因为名称 local 以不同的含义声明了两次:第一个是类型 struct sala 的别名,第二个是类型 [=18= 的别名].

这是第一个和第二个 typedef 声明之间的区别。:)

至于typedef声明的位置,则可以放在相应的结构体定义之前。与结构定义一起或在结构定义之后。

例如

typedef struct A A;
struct A
{
    int x;
};

typedef struct A
{
    int x;
} A;

struct A
{
    int x;
};

typedef struct A A;

这些声明之间的本质区别在于,如果您想在其定义中引用已定义的结构,那么在第二种和第三种情况下,您必须使用类型名称 struct A,因为 typedef 名称 A 是尚未申报。

例如

typedef struct Node Node;
struct Node
{
    int x;
    Node *next;
};

但例如

typedef struct Node
{
    int x;
    struct Node *next;
} Node;