[Algorithm] stack overflow of the main function

The main function of the size of the stack defaults to 1mb

If the array int x [1000] [1000] defined in the main function

Then int is 4byte, 8bit as 1byte, 1024byte as 1kb, 1024kb to 1mb

4 * 1000 * 1000/1024/1024 = 3.814697265625mb greater than 1mb,

Therefore, the definition of a stack overflow exception will be the main function

#include<bits/stdc++.h>
using namespace std;
int main(){
    int x[1000][1000];
    return 0; 
} 

 result

-------------------------------- 
Process the Exited the After 3.482 seconds The with return value 3,221,225,725 
Press any key to continue...

 

The solution is to define the array outside the main function static statically allocated storage space

It recommended to the array definition outside the main function in the contest

#include<bits/stdc++.h>
using namespace std;
int x[1000][1000];
int main(){
    return 0; 
} 

 

Guess you like

Origin www.cnblogs.com/LPworld/p/11904819.html