I have written the following code, which prints an array. But when the input is very large, for example J=40000, I get Segmentation fault. Could you tell me why it happens? Is this because the dimension of the arrays is too big, or have I done something wrong?
int main(){
int i,j,J;
printf("Give the number J: \n");
scanf("%d", &J);
double k[J-1];
double d[J-1];
double p[J-1];
double A[J-1][3];
double h=1.0/(double)J;
for(j=0; j<J-1; j++){
k[j]=-1.0/(h*h);
d[j]=2.0/(h*h);
p[j]=-1.0/(h*h);
}
for(j=0; j<J-1; j++){
A[j][0]=k[j];
A[j][1]=d[j];
A[j][2]=p[j];
}
A[0][0]=0.0;
A[J-2][2]=0.0;
for(j=0; j<J-1; j++){
for(i=0; i<3; i++){
printf("%lf ",A[j][i]);
}
printf("\n\n");
}
return 0;
}