1.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
double **memalloc(int M,int N);
main()
{
int i,j;
double **a;
a=memalloc(2,2);
printf("a\n");
for(i=0;i<2;i++)
{
printf("\n");
for(j=0;j<2;j++)
{
a[i][j]=i+j;
printf("%f\t",a[i][j]);
}
}
}
//FUNCTION-memalloc
double **memalloc(int M,int N)
{
int i;
double **y;
y = malloc(M* sizeof(double *));
if(y == NULL)
{
printf("out of memory\n");
return 0;
}
for(i = 0; i < M; i++)
{
y[i] = malloc(N * sizeof(double));
if(y[i] == NULL)
{
printf("out of memory\n");
return 0;
}
}
free y;
return y;
}
the line
free y
cause problems. should i use it after
return y
2. Is there any way to check whether the memory is freed?