一个很简单的静态链表,指针p的偏转为什么不能直接用p++而要用p=p->next?还有指针next的定义是什么原理,为什么可以直接在结构体的申明中定义结构体指针?
#include
struct weapon {
int price;
int atk;
struct weapon *next;
};
int main()
{
struct weapon a,b,c,*head,*p;
a.price=100;
a.atk=1000;
b.price=200;
b.atk=2000;
c.price=300;
c.atk=3000;
head=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
while(p!=NULL)
{
printf("%d %d\n",p->price,p->atk);
p=p->next;//p++;为什么不行?
}
return 0;
}