C ++: XCode EXC_BAD_ACCESS problem

I am new to C ++ coding in Xcode as my structure, so I would like to ask a question which, I believe, is only related to memory management

What I'm trying to achieve is that I am trying to create a matrix size of 10,000 x 10,000 , but even I am doing the correct coding (at least what I think), I just can't get it working, just indicating an error EXC_BAD_ACCESS .

You can find my code below. Is this an Xcode related error, or did I make an obvious coding error?

#include <iostream>
using namespace std;

    int main(int argc, const char * argv[])
    {

        // insert code here...
        int matrix[10000][10000];
        for(int i=0;i<10000;i++)
            for(int j=0;j<10000;j++)
                matrix[i][j]=24;
        cout<<"Done"<<endl;
        return 0;
    }
+3
source share
1 answer

Jesse Good , "int matrix[10000][10000]; ". .

, .

:

400,000,000 bytes = 10000*10000*sizeof(int)

:

#include <iostream>
#include <vector>

int main(int argc, const char* argv[]) {
    std::vector<std::vector<int> > matrix(10000, std::vector<int>(10000, 24));
    cout<<"Done"<<endl;
    return 0;
}

, . , . .

+5

All Articles