用C简单的前pression怪异输出,为什么呢? [英] Weird output of simple expression in C, why?
本文介绍了用C简单的前pression怪异输出,为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用TURBOC ++。我写的这是不是导致正确的评价如下EX pression,我错过了一些概念背后?
INT C = 300 *300分之300;
的printf(%D,C);
的输出是
81
块引用>为什么?
解决方案300 * 300 90000。
假设INT是16bit,你已经溢出。
溢出环绕,让您:
24464
。300分之24465= 81.55
的不要依赖于这一点。这是未定义的行为。的
I am using TurboC++. I write the following expression which is not resulting in proper evaluation, am I missing some concept behind it?
int c=300*300/300; printf("%d",c);
The output is
81
Why?
解决方案300*300 is 90000.
Assuming int is 16bit, you have overflowed.
The overflow wraps around, giving you:
24464
.24465/300 = 81.55
Do not rely on this. It is undefined behavior.
这篇关于用C简单的前pression怪异输出,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文