C语言
初识指针大小的决定因素;结构体简易用法并且结合所学创新
20分钟
#include <stdio.h>
int main()//指针的大小取决于地址线的大小,地址线的大小取决于电脑的位数64还是32
{
printf("%d\n", sizeof(int*));
printf("%d\n", sizeof(char*));
printf("%d\n", sizeof(short*));
printf("%d\n", sizeof(long*));
printf("%d\n", sizeof(long long*));
printf("%d\n", sizeof(float*));
printf("%d\n", sizeof(double*));
return 0;
}
(32位是4字节,64位是8字节)
#include <stdio.h>
struct student
{
char name[10];
int age;
float weight;
};
int main()
{
struct student a = { "张三",18,80.51 };
printf("1: %s %d %lf\n", a.name, a.age, a.weight);
struct student* ps = &a;
printf("2: %s %d %lf\n", (*ps).name, (*ps).age, (*ps).weight);
printf("3: %s %d %lf\n", ps->name, ps->age, ps->weight);
return 0;
}