#include<stdio.h>
#include<stdlib.h>
int **array();
main()
{
int **result=array(),i,j;
//display result
for(i=0;i<2;i++)
printf("\n");
for(j=0;j<2;j++)
printf("%d \t",result[i][j]);
}
//function
int **array()
{
int nrows=2,ncolumns=2,i,j;
// printf("hi");
//memory allocation
int **array;
array = malloc(nrows * sizeof(int *));
if(array == NULL)
{
printf("out of memory\n");
return 0;
}
//printf("hi");
for(i = 0; i < nrows; i++)
{
array[i] = malloc(ncolumns * sizeof(int));
if(array[i] == NULL)
{
printf("out of memory\n");
return 0;
}
}
//create array
for(i=0;i<2;i++)
for(j=0;j<2;j++)
array[i][j]=i+j;
//returning pointer
return array;
printf("hi");
}
it compiled successfully. but shows segmentation fault on running. please help to find error