定义变量:
int a;
int b;
double c;
变量的定义要给出变量类型以及变量名称。结构体变量也是如此。
结构体指针变量也是如此定义:
如果不知道指针可以先看看:简单介绍一下c语言指针
也就是说结构体的操作和普通变量的操作基本上是一样的。
struct Student* p;
struct Student XiaoMing;
p=&XiaoMing;
结构体变量的访问:
如果是变量类型,就用变量.成员访问。
如果是指针变量,采用指针->成员或者(*指针).成员的方式。
#include<stdio.h>
struct Student
{
char name[20];
char number[8];
float score;
int weight;
};
int main()
{
struct Student* p;
struct Student XiaoMing;
p=&XiaoMing;
p->weight=100;//采用(*p).weight=100; XiaoMing.weight=100;都可以
printf("%d\n",(*p).weight);
printf("%d\n",p->weight);
printf("%d\n",XiaoMing.weight);
}