1.结构体基本形式
struct 结构名
{
类型 变量名;
类型 变量名;
······
}结构变量;
结构名和结构变量都可以单独省略,例如:
struct student
{
int num;
};
struct student teacher;
struct
{
int num;
}teacher;
一般都是使用第一种模式,第二种模式一般使用在只在函数内部使用一次的情况,因为无名结构体无法再次声明
2.结构体搭配typedef使用
typedef struct student
{
int num;
}STUDENT;STUDENT teacher;
但是在使用的时候需要注意一点,如下声明方式:
typedef struct tagNode
{
char *pItem;pNode pNext;
} *pNode;
这种声明方式是错误的,因为声明pNext时使用了pNode ,而此时实际结构体还未声明,编译器实际还不理解pNode,因此会编译报错
需要调整声明方式
typedef struct tagNode
{
char *pItem;struct tagNode *pNext;
} *pNode;
(待补充)