这是数据结构一个链表初始化问题


#include<iostream>
#include<conio.h>
#include<string.h>
#define OK 1
#define MAXSIZE 100
using namespace std;
typedef  int Status;
#define OK 1
typedef  struct  
{
char name[5];
float price;    
}Book;

typedef  struct  LNode 
{
Book Elem;
LNode *next;

}LNode,*List;

Status InitList(LNode *L)
{
  L=new LNode();
  if(!L)
      exit(-1);
  else
    L->next=NULL;
  return OK;
}

int main()
{
LNode *L;

List LL;
InitList(L);
cout<<L->next;
getch();


return 0;
}

为什么输出L->next的值不为NULL,反而溢出呢?

Status InitList(LNode *L)
说了好多次了,要双指针

#include<iostream>
#include<conio.h>
#include<string.h>
#define OK 1
#define MAXSIZE 100
using namespace std;
typedef  int Status;
#define OK 1
typedef  struct  
{
char name[5];
float price;    
}Book;

typedef  struct  LNode 
{
Book Elem;
LNode *next;

}LNode,*List;

Status InitList(LNode **L)
{
  *L=new LNode();
  if(!(*L))
      exit(-1);
  else
    (*L)->next=NULL;
  return OK;
}

int main()
{
LNode *L;

List LL;
InitList(&L);
cout<<L->next;
getch();


return 0;
}