这是代码:
#include<stdio.h>
#define NULL 0
struct student
{
int num;
float score;
struct student *next;
};
int main(void)
{
struct student a, b, c, *head, *p;
a.num=99101;
a.score=89.5;
b.num=99103;
b.score=90;
c.num=99107 ;
c.score=85;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
printf("a=%d\nb=%d\n",a,b);
printf("b=%d\n",b);
do
{
printf("p->num=%d \n p->score=%5.1f\n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
return 0;
}
(看结果第三和第四行)
printf("a=%d\nb=%d\n",a,b);
printf("b=%d\n",b);
为什么两次输出的b不一样?
还有:如果把
do
{
printf("p->num=%d \n p->score=%5.1f\n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
改成:
do
{
printf("p=%d \n p->num=%d \n p->score=%5.1f\n",*p,p->num,p->score);
p=p->next;
}
while(p!=NULL);
输出的结果里p->num,p->score的值全改了
为什么会这样?? |