C
chinabooter2003
Dear members:
I am programming in C. I declare as follows but when running program,
there is a fatal error appear:
double a[255][255];
double b[255][255];
When I change it to
double a[255][255];
double b[255][100];
then it works.
I think the problem caused by the running out of memory.
But I am wondering why I use malloc function, there is no error:
------------------------
double **a;
double **b;
a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
-------------------------
I think I am using the same volume of memory for both version. Why in
the first case, the memory is insufficient of memory and in the other,
it is big enough.
One more thing, I need to use 2D array. I try the following but there
is always error when I try to access to an element of the 2D array:
double **a;
double **b;
a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
a[1][1]=1;<----- the error occurs
Pleas take a look and point out the error for me. or can you please
suggest me other more effective methods to use 2D array?
Thank you very much and look forward to your answer.
SIncerly yours
I am programming in C. I declare as follows but when running program,
there is a fatal error appear:
double a[255][255];
double b[255][255];
When I change it to
double a[255][255];
double b[255][100];
then it works.
I think the problem caused by the running out of memory.
But I am wondering why I use malloc function, there is no error:
------------------------
double **a;
double **b;
a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
-------------------------
I think I am using the same volume of memory for both version. Why in
the first case, the memory is insufficient of memory and in the other,
it is big enough.
One more thing, I need to use 2D array. I try the following but there
is always error when I try to access to an element of the 2D array:
double **a;
double **b;
a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
a[1][1]=1;<----- the error occurs
Pleas take a look and point out the error for me. or can you please
suggest me other more effective methods to use 2D array?
Thank you very much and look forward to your answer.
SIncerly yours