#include<stdio.h>
#include<stdlib.h>
struct student{
int num;
char name[20];
char sex;
};
int main(void)
{
struct student s = {1001,"wangle",'M'};
struct student sarr[3] = { 1001, "lilei", 'M', 1005, "zhangsan", 'M', 1007, "lili", 'F' };
struct student *p;
int num;
p = &s;
printf("%d %s %c\n",p->num,p->name,p->sex);
p = sarr;
printf("%d %s %c\n",(*p).num,(*p).name,(*p).sex);
printf("%d %s %c\n",p->num,p->name,p->sex);
printf("----------------------------------\n");
num = p->num++; //等价于1.num=p->num; 2.p->num=p->num+1;
printf("num=%d p->num=%d\n", num, p->num);
num = p++->num; //等价于1.num = p->num; 2.p=p+1;
printf("num=%d p->num=%d\n", num, p->num);
return 0;
}
运行结果:
1001 wangle M
1001 lilei M
1001 lilei M
----------------------------------
num=1001 p->num=1002
num=1002 p->num=1005
请按任意键继续. . .