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

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

问题描述

例如,

int result;

result = 125/100;

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 behavior?

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

Yes, integer quotient of the two operands.

6.5.5乘法运算符

6 除以整数时,/运算符的结果是代数商 88)如果商a/b可表示,则表达式 (a/b)* b + a%b等于a.

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.

和相应的脚注:

88)这通常被称为向零截断".

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

当然要注意两点:

3 通常对操作数进行算术转换.

3 The usual arithmetic conversions are performed on the operands.

和:

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

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.

[注意:重点是我的

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

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