结构体
//结构体
//char int double...
//人 = 3.14
//'w'
//书 - 复杂对象
//名字 + 身高 + 年龄 +身份证号码+......
//书名+作者+出版社+定价+书号......
//复杂对象 - 结构体 - 我们自己创造出来的一种类型
//struct - 结构体关键字
//创建一个结构体类型
struct Book {
char name[20];//C语言程序设计
short price;//55
};
int main() {
//利用结构体类型创建一个该类型的结构体变量
struct Book b1 = {"C语言程序设计",55};
strcpy(b1.name, "C++");//strcpy - string copy - 字符串拷贝 - 库函数 - string.h
//struct Book* pd = &b1;//pd内存储的是b1的地址
//利用pd打印出我的书名和价格
//. 结构体变量.成员
//-> 结构体指针->成员
//printf("%s\n", pd->name);//pd是指针 指针指向对象的成员
//printf("%d\n", pd->price);
//printf("%s\n", (*pd).name);//*pd解引用 - b1的值
//printf("%d\n", (*pd).price);
//printf("书名:%s\n", b1.name);
//printf("价格:%d\n", b1.price);
//b1.price = 15;
//printf("修改后的价格:%d\n", b1.price);
return 0;
}
int main() {
printf("%d\n", sizeof(char*));//
printf("%d\n", sizeof(short*));
printf("%d\n", sizeof(int*));
printf("%d\n", sizeof(double*));
double d = 3.14;
double* pd = &d;//32位操作系统下是4个字节,64位操作系统下是8个字节
printf("%d\n", sizeof(pd));
*pd = 5.5;
printf("%lf\n", d);
printf("%lf\n", *pd);
int a = 10;//申请了4个字节的空间
//printf("%p\n",&a);
int* p = &a;//p是一个变量 - 指针变量
//printf("%p\n", p);
*p = 20;//* - 解引用操作符/间接访问操作符
printf("a = %d\n", a);
return 0;
}