What is wrong with the following code?
(以下代码有什么问题?)
It generates a Segmentation fault. (它将生成分段错误。)
#include <stdio.h>
#include <stdlib.h>
typedef struct{
int ** access;
}item;
int main()
{
int access[5][5];
for(int i = 0; i < 5; i++){
for(int j = 0; j<5; j++){
access[i][j] = 5;
}
}
item * p = malloc(sizeof(item));
p->access = access;
for(int i = 0; i < 5; i++){
for(int j = 0; j<5; j++){
printf("%d",p->access[i][j]);
}
}
return 0;
}
I want to create a struct that contains the value of a double array created in the main function.
(我想创建一个包含在main函数中创建的double数组的值的结构。)
What is wrong with it? (怎么了)
ask by Billy translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…