0
我用C新的,我寫了下面的代碼爲結構指針分割故障
#include <stdlib.h>
#include<stdio.h>
typedef struct
{
int name1;
}check1;
typedef struct
{
int name2;
}check2;
int main()
{
check1 *test1;
check2 *test2;
test1->name1=1;
test2->name2=2;
return 0;
}
當我執行它,它給我的錯誤:
$ gcc test1.c
$ ./a.out
Memory fault
在GDB: -
Program received signal SIGSEGV, Segmentation fault.
0x000000000040045e in main()
可能是什麼原因?
謝謝。