奇怪的现象....
#include<iostream.h>
typedef struct node
{
int music[5];
char name[10];
int i;
struct node *next;
};
void set(node *p)
{
node *s=new node;
s=p;
s->next=NULL;
node m1={{1,2,3,4,5},"小蜜蜂",1,NULL};
node *s1=new node;
s1=&m1;
s->next=s1;
node m2={{5,4,3,2,1},"遇见",2,NULL};
node *s2=new node;
s2=&m2;
s1->next=s2;
}
int length(node *p)
{
int n=0;
node *q=p->next;
while(q!=NULL)
{
n++;
q=q->next;
}
return n;
}
void display(node *p)
{
int n=length(p),a;
node *q=p->next;
cout<<"歌曲库显示\n";
for(a=1;a<=n;a++)
{
cout<<a<<'.'<<q->name<<endl;
q=q->next;
}
}
void main()
{
node hebe;
set(&hebe);
display(&hebe);
}
大家来看看啊...为什么编译能通过..运行时却是非法操作?