本文介绍了当你的逻辑不是浮动会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为这只是返回一个int。还有什么事情我应该知道的? C / C ++区别在哪里?

 浮动= 2.5;
!一个; //这是什么回报?诠释?浮动?


解决方案

对于C ++,引用C ++ 11§5.3.1/ 9:

So what's really relevant here is the behavior of static_cast<bool>(some_float) – quoting §4.12/1:

Putting those together, 2.5f is a non-zero value and will consequently evaluate to true, which when negated will evaluate to false. I.e., !a == false.


Regarding C, quoting C99 §6.5.3.3/5:

I.e. the net result is the same as with C++, excepting the type.

这篇关于当你的逻辑不是浮动会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 10:50