结构体
1.人 书 复杂对象
身高 名字 年龄 身份证号码
2.结构体 我们自己创造出来的一种类型
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
struct Book //创建一个结构体类型
{
char name[20];
short price;
};
int main()
{
struct Book b1 = { "云边有小卖铺", 10 }; //利用结构体类型创建一个结构体类型变量
struct Book *pb = &b1;
printf("%s\n", pb->name); // . 结构体变量 . 成员
printf("%d\n", (*pb).price); // -> 结构体指针 -> 成员
return 0;
}

#include <stdio.h>
#include <string.h>
struct Book //创建一个结构体类型
{
char name[20];
short price;
};
int main ()
{
struct Book b1 = { "云边有小卖铺", 10 };//利用结构体类型创建一个结构体类型变量
strcpy (b1.name, "c++"); //strcpy-string copy --字符串拷贝--库函数--string.h
//改名字
struct Book *pb = &b1;
printf("%s\n", pb->name);
printf("%d\n", (*pb).price);
printf("书名:%s\n", b1.name);
printf("价格:%d元\n", b1.price);
b1.price = 6; //改价格
printf("全场清仓甩卖价%d元\n",b1.price);
return 0;
}


浙公网安备 33010602011771号