直接运行与调试运行退出代码不一样,但运行结果是一样的

直接运行:
退出代码-1073740940 (0xC0000374)
调试出来:
退出代码0
这是什么原因?

#include 
#include 
#include 
#include 

typedef struct SL
{
    int *elem;
    int TableLen;
}SSTable;

//随机数的生成
void ST_Init(SSTable &ST,int len)
{
    ST.TableLen=len;
    ST.elem= (int*)malloc(sizeof (SSTable));
    int i;
    srand(time(NULL));
    for (i=0;irand()%100;
    }
}

void ST_print(SSTable ST)
{
    for(int i=0;iprintf("%5d",ST.elem[i]);
    }
    printf("\n");
}

//两个数的交换
//交换时要取地址
void swap(int &a,int &b)
{
    int temp;
    temp=a;
    a=b;
    b=temp;
}


//大根堆
void LargeRootPile(int A[],int j,int len)
{
    int dad=j;

    int son=2*dad+1;
    while (son//!容易出错
    {
        if (son+11])
        {
            son++;
        }
        if (A[son]>A[dad])
        {
            swap(A[son],A[dad]);
            dad=son;
            son=2*dad+1;
        }else
        {
            break;
        }
    }


}


//先将A变成大根堆
void HeapSort(int A[],int len)
{
    int i;
    //使得A成为大根堆
    for(i=len/2-1;i>=0;i--)//i取0的时候还是有的
    {
        LargeRootPile(A,i,len);
    }
    //A成为大根堆后就要根头与叶尾进行交换
    swap(A[0],A[len-1]);
    //根头与叶尾进行交换后,继续进行变成大根堆,继续交换;
    //
    for(i=len-1;i>1;i--)
    {
        LargeRootPile(A,0,i);//大根堆长度减1了,不会影响后面交换数时,把交换过的又交换
        //这时候是从头根进行大根堆,不是从最后一个父亲根进行大根堆;
        swap(A[0],A[i-1]);//进行交换时,这里的要进行大根堆总数长度已经改变了
    }

}

int main() {
    SSTable ST;
    ST_Init(ST,10);

    //将A固定,还不是随机数去用
    int A[10]={ 3, 87, 2, 93, 78, 56, 61, 38, 12, 40 };
    memcpy(ST.elem,A,sizeof (A));//头文件是#include 

    ST_print(ST);
    HeapSort(ST.elem,10);
    ST_print(ST);
    return 0;
}


我觉得是内存溢出的问题,试着malloc一下elem元素空间

第16行应为:ST.elem = (int*)malloc(sizeof(int) * len); // 原代码:ST.elem = (int*)malloc(sizeof(SSTable));

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^