结构体主要成员运算符有"."和" -"多用于修改结构成员的值。以下是具体的例子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);}
反正你记住,若是指针就用->,若是结构名就用.就是了.这个是成员操作符,控制具体的成员.
结构体主要成员运算符有"."和" ->"
多用于修改结构成员的值。
以下是具体的例子
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);
}