1.指针
#include<stdio.h>
int main()
{
int a = 10; //a在内存中分配地址--4个字节
printf("%d\n", &a); //打印a的地址
int* b = &a; //b是用来存放地址的,在C语言中b叫做指针变量
printf("%d\n", *b);
* b = 20; //指针变量*b通过b里面的地址找到a
printf("%d\n", a);
return 0;
}
2.结构体可以让C语言创建新的类型
#include<stdio.h>
//创建一个学生
struct stu{
char name[20]; //名字 结构体变量
int age; //年龄
float score; //成绩
};
//创建一本书
struct book {
char name[20]; //名字
float price; //价格
} ;
int main()
{
struct stu a = { "张三",20,85.5 }; //结构体的创建和初始化
printf("1:%s %d %f\n", a.name, a.age, a.score);//结构体变量.成员变量
struct book c = { "红楼梦",35.7};
printf("2:%s %f\n", c.name,c.price);
//指针
struct stu * b = &a;
printf("3:%s %d %f\n", (*b).name, (*b).age, (*b).score); //(*指针变量).成员变量
struct book* d = &c;
printf("4:%s %f\n", d->name, d->price); //指针变量->成员变量
return 0;
}