Hello
I think this is easy for experienced C++ users.
I want to define and initialize a [512][512] matrix.
The problem is that when I do int matrix[512][512] I get an error and the program it shuts down.
I think this has to do with max reserve memory.
What can I do?
Thank you

Hello
I think this is easy for experienced C++ users.
I want to define and initialize a [512][512] matrix.

You probably don't. Tell us why you think you should.

The problem is that when I do int matrix[512][512] I get an error and the program it shuts down.
I think this has to do with max reserve memory.
What can I do?

Tell us what the error says.
If you declare an int array that's 512*512*4 bytes (asssuming 32 bit OS), that would result in exactly 1 MB memory use, so that shouldn't really be a problem. (assuming you have a PC from the past 10-15 years)

Yeah, I tried this, it was compiling ...
I stored a value in it but when displaying with cout it didn't display anything ...

You're probably better off with a vector:

// Create
vector< vector<int> > vec(512, vector<int>(512));
// Write
vec[2][3] = 10;

I initialize the matrix as following and when then I cout, the program crashes...

int matrix[512][512];
for(i=0;i<512;i++){
for(j=0;j<512;j++){

matrix[i][j]=-1;
}
}

cout<<matrix[100][100]<endl;

>>I initialize the matrix as following and when then I cout, the program crashes..
Look at the <endl it should be <<endl
Are i and j defined?
Try running this code on your compiler;

int matrix[512][512];
for(int i=0;i<512;i++){
for(int j=0;j<512;j++){

matrix[i][j]=-1;
}
}

cout<<matrix[100][100]<<endl;

Thanks you boys. The only way was to use vector as "tux4life" suggested. Thank everybody.Although I cant understand way the program crashes I will mark this thread as solved.Thanks