我使用代码块。
当代码为:
printf("%d",1/0);
程序无法运行,出现错误。但是当我写这个时:
printf("%d",1/0.0);
程序可以运行,输出为0
。我想知道为什么。
最佳答案
1/0
或 1/0.0
都是未定义的行为:
C11 §6.5.5 Multiplicative operators
The result of the
/
operator is the quotient from the division of the first operand by the second; the result of the%
operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.
关于c - 为什么 printf ("%d",1/0.0) 的输出是 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342357/