->这个符号是结构体运算符
每一个结构体变量中的各个成员,都可以通过结构体成员运算符“.”或“->”来逐个访问。
例如:
定义一个结构体
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);
}


相关文章:

  • 2021-04-22
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
相关资源
相似解决方案