Why does the compiler not show an error when we try to divide a variable by zero

前端 未结 5 600
野的像风
野的像风 2021-01-06 08:20

If we try to run this code:

int d = 10/0;

We get a compiler error. So we cannot divide by zero.

Now consider this code:

<         


        
5条回答
  •  一整个雨季
    2021-01-06 08:56

    Because your d variable is not constant.

    Compiler does only basic (let say trivial) math checks. Your is not basic enough to be done by compiler, because it uses variable that is not const.

提交回复
热议问题