I am trying to read a data file containing about 10^7 values and perform some calculations. I am creating an array of that size and doing fscanf to read those values into each of the elements of the array. The gist of the program looks like this
#include<stdio.h>
#include<math.h>
int main()
{
    int L = 10000000;
    float array[L];
    FILE *fp;
    fp = fopen("datafile.txt","r");
    /*
    reading values into the array from datafile.txt using fscanf
    and doing some operations on array elements
    */
    fclose(fp);
    return 0;
}
But the same program works if I use L of lesser magnitude, i.e for L=10^6 and lesser it works fine.
Firstly I thought I have lesser primary memory on my laptop (~4GB) then I tried to run the program on high-end computers having 16GB and 128GB main memory there also I got segmentation fault(core dumped)
I used gcc to compile the program which compiled the program without any error and warnings.
gcc my_program.c -lm
./a.out
The output was segmentation fault as I mentioned.
 
    