Process returned -1073741571 (0xC00000FD) Program received signal SIGSEGV, Segmentation fault.

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/h2453532874/article/details/77855672

今天写了一个平衡二叉树的代码,详情见附件。在我运行时报错Process returned -1073741571 (0xC00000FD),调试的时候报错Program received signal SIGSEGV, Segmentation fault.

意思大概就是内存泄漏,和指针有关。碰到这样的问题一定要注意你定义指针的地方,检查是否出现以下错误:

1.

struct node
{
int data;
}*p;

p->data=2;
  错误分析: 典型定义了指针忘了初始化就使用。在使用指针的时候明确指向。


2.

这个就比较蛋疼了,第一次遇到很难发现,编译没错,运行调试都报错。

AVLnode InsertNode(int x,AVLnode A)
{
    if( !A )
    {
        AVLnode A=new struct BinaryNode();//注意
        A->data=x;
        A->left=A->right=NULL;
        return A;              
    } 
}
int main()
{
    int n,tmp;

    AVLnode T=(AVLnode)malloc(sizeof(struct BinaryNode));//错 

    cin>> n;
    for(int i=0;i<n;i++)
    {
        cin>>tmp;
        T=InsertNode(tmp,T);
    }
    return 0;
}
我两次定义不同指针指向同一个结构体!!!


解决办法,把主程序的该为

 AVLnode T=NULL;//你按照自己程序该



猜你喜欢

转载自blog.csdn.net/h2453532874/article/details/77855672