I am new to c programming. I have a program which tests how much time does it take to compute a series of 3 nested loop and calculation inside it whenever i try to run this code it causes segmentation fault. Here is the code and debug info:
#include <stdio.h>
#include <sys/time.h>
#define EXIT_SUCCESS 0;
int main(void){
struct timeval start,end;
gettimeofday(&start, NULL);
int n = 100;
int sum[n][n][n];
int firstNum[n][n][n];
int secondNum[n][n][n];
for(size_t a=0;a<n;a++){
for (size_t b = 0;b<n;b++){
for (size_t c=0;c<n;c++){
firstNum[a][b][c] = c;
secondNum[a][b][c] = 1;
sum[a][b][c] = firstNum[a][b][c] + secondNum[a][b][c];
}
}
}
gettimeofday(&end, NULL);
double timeTook = (end.tv_sec - start.tv_sec)*1000.0;
printf("Time took: %f\n", timeTook);
return EXIT_SUCCESS;
}
Debug info
Program received signal SIGSEGV, Segmentation fault.
main () at /home/ayush/Desktop/Project/trial.c:16
16 secondNum[a][b][c] = 1;
I want to know what is causing this error I am accessing the arrays index within the memory bound but it still causes segmentation fault.