什么是整数除法C中的行为吗? [英] What is the behavior of integer division in C?

查看:158
本文介绍了什么是整数除法C中的行为吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

  INT的结果;结果=一百分之一百二十五;

 结果= 73,45;

将导致永远是分裂的地板?什么是定义的行为?


解决方案

  

将导致永远是分裂的地板?什么是定义bahavior?


是的,两个操作数的整数商。


  

6.5.5乘法运算符


  
  

6 :当整数划分,/运算的结果是代数商与任何
  小数部分被丢弃。 88)如果商A / B重新presentable,前pression
  (A / B)* B + A%B应等于一。


和相应的脚注:


  

88),这通常被称为''截断向零'。


当然两点需要注意的是:


  

3 常见的算术转换的操作数执行。



  

5 /运算符的结果是
  从除法商数
  第一个操作数由第二;该
  %操作的结果是
  余。 在这两种操作中,如果
  第二个操作数的值是零,
  该行为是不确定的。


[注:重点煤矿]

For example,

int result;

result = 125/100;

or

result = 43/100;

Will result always be the floor of the division? What is the defined behavior?

解决方案

Will result always be the floor of the division? What is the defined bahavior?

Yes, integer quotient of the two operands.

6.5.5 Multiplicative operators

6 When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.88) If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a.

and the corresponding footnote:

88) This is often called ‘‘truncation toward zero’’.

Of course two points to note are:

3 The usual arithmetic conversions are performed on the operands.

and:

5 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.

[Note: Emphasis mine]

这篇关于什么是整数除法C中的行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆