c - 为什么会出现运行时错误?代码仍然给我正确的输出

标签 c runtime-error

为什么我在运行这段代码时会遇到运行时错误? 这是一个测试输入案例:

5 3
1 2 100
2 5 100
3 4 100
#include <stdio.h>
long long int s[999999];
// Complete the arrayManipulation function below.
int main()
{
    int n,m,i;
    long int a,b,val,cval;
    scanf("%d %d",&n,&m);
    for(;m>0;m--)
    {
        scanf("%ld %ld %ld",&a,&b,&val);
        s[a-1]+=val;
        if(b!=n)
            s[b]-=val;
    }
    val=s[0];
    cval=s[0];
    for(i=1;i<n;i++)
    {
        cval+=s[i];
        if(val<cval)
            val=cval;
    }
    printf("%ld",val);
    return val;
}

预期和实际结果匹配,但编译器给出运行时错误。

最佳答案

应用程序的return 语句通常应返回EXIT_SUCCESS (0) 或EXIT_FAILURE (1)。

您返回一个非常正的值 - 这意味着 shell 认为这是一个错误。只需将返回值更改为“0”或 EXIT_SUCCESS 即可消除“运行时错误”。

另见: What should main() return in C and C++?

关于c - 为什么会出现运行时错误?代码仍然给我正确的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57302789/

相关文章:

c - 通过引脚连接时,USB 端口无法识别微 Controller

C - Gdb 不让我看到堆栈内存中的值

c - 错误 :invalid type argument of '->' (have 'Queue {aka struct Queue}

python - 在 OpenCV+Python 中使用 knnMatch 时出错

c - 我无法理解这个段错误

c++ - Linux。不打印到文件

c - Redis 模块 RESTORE 命令调用

c - 在 libharu C 中动态添加页面

delphi - delphi TFileStream“内存不足”

python - 运行时错误: The classifier does not expose "coef_" or "feature_importances_" attributes