int main()
{
int a=1;
int *b;
typedef struct
{
int no;
char nn;
}L;
L *LL;
LL->no=1;
printf("%d",LL->no);
getch();
return 0;
}
这是我写的代码,代码没有报错,为什么运行的时候会溢出呢?
int main()
{
int a=1;
int *b;
typedef struct
{
int no;
char nn;
}L;
L *LL;
LL->no=1;
printf("%d",LL->no);
getch();
return 0;
}
这是我写的代码,代码没有报错,为什么运行的时候会溢出呢?
动态内存没分配;
L *LL;
改成
L *LL = (L *)malloc(sizeof(L));
全部代码:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h>
int main()
{
typedef struct
{
int no;
char nn;
}L;
L *LL = (L *)malloc(sizeof(L));
LL->no=1;
printf("%d",LL->no);
free(LL);
LL = NULL;
getch();
return 0;
}