学无先后,达者为师

网站首页 编程语言 正文

3 Segmentation fault (core dumped) ./a.out Exited with error status 139的决解办法

作者:Austinu 更新时间: 2022-03-15 编程语言

出现错误的原因是空指针

通过以下实例说明

#include <stdlib.h>	
#include<stdio.h>
	int main()
	{
	    int *m;     //默认初始化为NULL
	    printf("It' OK here.\n");
	    printf("*m = %d\n",*m);   //使用NULL指针导致segmentation fault.
	    printf("Is here OK?\n");
	    return 0;
	}

运行结果:
在这里插入图片描述

决解办法:分配内存

int *m = (int *)malloc(sizeof(int))

运行结果:
在这里插入图片描述

原文链接:https://blog.csdn.net/Austin_/article/details/108922880

栏目分类
最近更新