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. What is wrong with it?