zoukankan      html  css  js  c++  java
  • 【算法】main函数的堆栈溢出

    main函数的堆栈的大小默认为1mb

    如果把数组int x[1000][1000]定义在main函数里

    则int为4byte,8bit为1byte,1024byte为1kb,1024kb为1mb

    4*1000*1000/1024/1024=3.814697265625mb大于1mb,

    所以定义在main函数中会出现堆栈溢出的异常

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

     结果

    --------------------------------
    Process exited after 3.482 seconds with return value 3221225725
    请按任意键继续. . .

    解决办法是将数组定义在main函数外static静态分配储存空间

    建议在竞赛中尽量将数组定义在main函数外

    #include<bits/stdc++.h>
    using namespace std;
    int x[1000][1000];
    int main(){
        return 0; 
    } 
  • 相关阅读:
    python 之Twsited
    python之 rabbitmq
    python 之redis
    异常处理
    python select
    线程与进程
    初识socket
    Position属性
    Http协议理解
    BFC(块级格式化上下文)
  • 原文地址:https://www.cnblogs.com/LPworld/p/11904819.html
Copyright © 2011-2022 走看看