结构体运算符(->)
->这个符号是结构体运算符
每一个结构体变量中的各个成员,都可以通过结构体成员运算符“.”或“->”来逐个访问。
例如:
定义一个结构体
struct student
{
char name[10];
char number[10];
float score;
}stu1;
然后访问其中成员,比如给成员赋值
stu1.score=65.5;
同样也可以写成
stu1->score=65.5;
struct date{
int year;
int month;
int day;
};
int main(int argc, char* argv[])
{
char end;
struct date today;
struct date* pdate;
pdate=&today;
today.year=2011;
today.month=2;
today.day=1;
printf("year = %d\n\n",today.year);
printf("month = %d\n\n",today.month);
printf("day = %d\n\n",today.day);
printf("year = %d\n\n",pdate->year);
printf("month = %d\n\n",pdate->month);
printf("day = %d\n\n",pdate->day);
}