1、定义结构体的同时定义变量
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
// 1、定义结构体的同时定义变量stu
struct Student
{
int age;
char* name;
} stu;
2、 定义结构体之后再定义变量
//2、 定义结构体之后再定义变量
struct Student
{
int age;
char* name;
};
struct Student stu;
3、定义结构体,但不定义结构体名字
/*3、定义结构体,但不定义结构体名字,只需要stu变量,
*后面不需要用结构体名定义其它变量时可以这样操作,
*但是后面没法定义新的变量
*/
struct
{
int age;
char* name;
}stu;
4、typedef 定义struct Student 结构体类型
// 4、typedef 定义struct Student 结构体类型
typedef struct
{
int age;
char* name;
} Student;
// 此时Student是结构体类型,使用前先定义一个变量stu
Student stu;