Struct in C

Declaration

struct is keyword for struct

Generally

1
2
3
struct tag_name {
// members
};

Note: Two of tag_name, member-list and variable-list must present.

Using typedef

1
2
3
4
5
6
7
8
9
typedef struct
{
int a;
char b;
double c;
} Simple2;

//现在可以用Simple2作为类型声明新的结构体变量
Simple2 u1, u2[20], *u3;

Usage

1
2
3
4
5
6
7
8
struct COMPLEX
{
char string[100];
// Other struct
struct SIMPLE a;
// Pointer to itself
struct COMPLEX *next_node;
};