Seg Fault when initializing array

后端 未结 6 565
忘了有多久
忘了有多久 2020-12-11 03:57

I\'m taking a class on C, and running into a segmentation fault. From what I understand, seg faults are supposed to occur when you\'re accessing memory that hasn\'t been all

6条回答
  •  囚心锁ツ
    2020-12-11 04:27

    I was unable to find any error in your code, so I compiled it and run it and worked as expected.

    You have, however, a semantic error in your code:

       start=clock();
       //set it up to perform the test 100 times.
       for(int k = 0; k<10; k++)
       {
    

    Should be:

       //set it up to perform the test 100 times.
       for(int k = 0; k<10; k++)
       {
       start=clock();
    

    Also, the condition at the end should be changed to its inverse:

    if(rowMajor

    Finally, to avoid the problem of the os-specific stack size others mentioned, you should define your matrix outside main():

    #include 
    #include 
    
    int majorArray [1000][1000];
    
    int main(void){
       //first define the array and two doubles to count elapsed seconds.   
       double rowMajor, colMajor;
       rowMajor = colMajor = 0;
    

提交回复
热议问题