在结构体中什么时候用"."与"->"最近有点纠结了,写了个小程序加以区分;
#include <stdio.h>
#include <stdlib.h>
typedef struct student {
int score;
}student,*ST;
int main(){
struct student p, *q;
p.score = 80;
q = (ST)malloc(sizeof(student));
q->score = 90;
printf("%d",p.score);
printf("%d",q->score);
free(q);
}
程序中的q->score可以换成(*q).score;
(*q)某种意义上可以看成是p;