struct node
{
int data;
node* next;
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
node* temp;
temp->data=5;
temp->next=0;
cout<<temp->data;
return 0;
}
没有在堆中分配内存,为什么此代码起作用。如果正确,为什么我们要在堆中分配内存以在链表中创建节点。