1. typedef struct {…};
typedef struct Student
{
int a;
int b;
}SqList;
int main(){
SqList d;
SqList *p=&d;
(*p).a=0;
p->a=0;
return 0;
}
1.结构体
- Student是一个类Class(属于同类的变量,会拥有相同的structure)
- SqList用于定义属于类Student的变量d
- d是变量
- typedef 是变量的类定义块
2.指针
p
是&d的指针,记录了变量d
的地址*p
相当于d,所以(*p).a
等价于d.a
p->a
也等价于d.a
,推荐这种写法
2. struct {…};
struct Student{
int a;
int b;
};
int main(){
struct Student SqList;
struct Student *p=&SqList;
p->a=3;
printf("%d",p->a);
return 0;
}
1.结构体
- Student是类
- SqList是类的变量
- 定义指针p需要写上struct Student
2.指针
p
是&SqList的指针,记录了变量d
的地址*p
相当于SqList,所以(*p).a
等价于SqList.a
p->a
也等价于SqList.a
,推荐这种写法