typedef语法澄清

Rub*_*byR 2 c struct

我在下面的声明中有点混淆 - 你能帮忙清理一下吗?

typedef struct {
  int a;
  int b;
} example;
Run Code Online (Sandbox Code Playgroud)

还有这个

struct something {
  int a;
  int b;
} ob;
Run Code Online (Sandbox Code Playgroud)

我不确定下面甚至是什么意思?

typedef struct foo {
  int a;
  int b;
} bar;
Run Code Online (Sandbox Code Playgroud)

Rei*_*ica 5

typedef struct {
  int a;
  int b;
} example;
Run Code Online (Sandbox Code Playgroud)

这个定义了一个未命名的结构类型,并example作为该结构类型的类型别名引入.因此,您只能将该结构类型称为"示例".

struct something {
  int a;
  int b;
} ob;
Run Code Online (Sandbox Code Playgroud)

这个定义了一个结构类型something,并声明了ob该类型的对象.您只能将结构类型称为struct something.

typedef struct foo {
  int a;
  int b;
} bar;
Run Code Online (Sandbox Code Playgroud)

这个定义了一个名为的结构类型,foobar作为该结构类型的类型别名引入.您可以将该结构类型称为struct foobar.