There is a weird segmentation fault error. The following code runs fine
#include
#include
main()
{
int matrixSize = 100
You are exceeding the stack size most likely.
In the terminal you are using to run this, try typing
ulimit -s unlimited
and re-run, assuming you are on a Linux system using bash (or sh).
If you have to use arrays that size, you can make them dynamic so they are on the heap rather than the stack if changing the stack size is problematic for some reason.
As tpg2114 says allocating as large matrices is not a good idea. Easiest is to allocate it like that
double (*a)[matrixSize] = malloc(sizeof(double[matrixSize][matrixSize]));
.
free(a);
Then you can continue to use your nested for
loops for initialization without problems as before.
NB:
main
is not conforming to the standard. In your
case you should use int main(void) { ... }
. since a conforming compiler should capture this, it looks that you don't use the correct options for your compiler or that you ignore warnings that he gives you.matrixSize
, i
and j
should be of type size_t
and not int
.