oj上做题runtime error可能的原因

oj上做题runtime error可能的原因

原文链接

runtime error (运行时错误)就是程序运行到一半,程序就崩溃了。

比如说,

①除以零

②数组越界:int a[3]; a[10000000]=10;

③指针越界:int * p; p=(int *)malloc(5 * sizeof(int)); *(p+1000000)=10;

④使用已经释放的空间:int * p; p=(int *)malloc(5 * sizeof(int));free(p); *p=10;

⑤数组开得太大,超出了栈的范围,造成栈溢出:int a[100000000];

一般来说,在oj上做题都把数组设成全局变量,减少5出现的可能。

有的时候再出现这样的错误还会给提示:

Runtime Error(ARRAY_BOUNDS_EXCEEDED) // array bounds exceed 数组越界

Runtime Error(DIVIDE_BY_ZERO) //divisor is nil 除零

Runtime Error(ACCESS_VIOLATION) //illegal memory access 非法内存读取

Runtime Error(STACK_OVERFLOW) //stack overflow 系统栈过载

这样可以照着上面查找错误。

友情链接:
Copyright © 2022 暴击魔方福利站 All Rights Reserved.