1.结构体概念
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//声明结构体
struct Student //student结构体名
{
char name[32]; //不要写成 char name[32] = {0};
int age;
char sex;
};
int main()
{
struct Student s1; //定义结构体变量
struct Student s2 = {"aaaaa", 20, 'm'}; //初始化结构体变量
//s1.name = "bbbb";
strcpy(s1.name, "bbbb");
s1.age = 22;
s1.sex = 'm';
//打印结构体变量,逐个打印
printf("%s %d %c\n", s1.name, s1.age, s1.sex); //通过结构体变量访问结构体成员,用符号 .
printf("%s %d %c\n", s2.name, s2.age, s2.sex); //通过结构体变量访问结构体成员,用符号 .
struct Student *s3; //结构体指针
s3 = (struct Student *)malloc(sizeof(struct Student));
strcpy(s3->name, "cccc");
s3->age = 24;
s3->sex = 'm';
printf("%s %d %c\n", s3->name, s3->age, s3->sex);
scanf("%s", s1.name); //不需要取地址
scanf("%s",