Hi there, There is a weird segmentation fault error. The following code runs fine Code: #include <stdlib.h> #include <stdio.h> main() { int matrixSize = 1000; int i,j; double a[matrixSize][matrixSize]; for (i = 0; i < matrixSize; i++) for (j = 0; j < matrixSize; j++) a[i][j] = rand() % 10; double b[matrixSize][matrixSize]; for (i = 0; i < matrixSize; i++) for (j = 0; j < matrixSize; j++) b[i][j] = rand() % 10; return 0; } But when I try to initialize one more 2D array, I get "segmentation fault" exception: Code: #include <stdlib.h> #include <stdio.h> main() { int matrixSize = 1000; int i,j; double a[matrixSize][matrixSize]; for (i = 0; i < matrixSize; i++) for (j = 0; j < matrixSize; j++) a[i][j] = rand() % 10; double b[matrixSize][matrixSize]; for (i = 0; i < matrixSize; i++) for (j = 0; j < matrixSize; j++) b[i][j] = rand() % 10; return 0; } Any advice on what can be a potential cause would be greatly appreciated.. Thank you in advance.
I can't see any difference between the two code samples. However I think I might have an idea. How much stack space do you have? In particular, do you have enough for 1000*1000*sizeof(double)*2 bytes? That's 8MB if sizeof(double) is 4.