c++避坑指南-除数为0

编写除法计算时,一定要注意判断除数是否为0

这条比较简单

 如下:

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
    int d = 0;
    float result = 100/d;
    cout << result << endl;
    return 0;
}

程序coredump

解决方法:

在除法语句执行前去判断除数是否为0

posted @ 2022-07-09 10:03  飞天赤狐  阅读(312)  评论(0)    收藏  举报