编译器对我的类型转换方法做什么 [英] what does the compiler do on my method concerning type conversion

查看:139
本文介绍了编译器对我的类型转换方法做什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我感谢你能告诉我编译器对我的方法有什么影响。如果我用 Area(10.1.10.1); 调用它,它返回我 102 。所以 .01 得到切割?你有一个好的网站,我可以得到关于这个特定的主题的信息?

Hey, I appreciate if you could tell me what the compiler does on my method. If I call it with Area(10.1,10.1); it returns me 102. So the .01 get cut? Do you have a good site where I can get information about this particular topic? thx for your time!

float Area (float length, float width){
int result;
result = length*width;
return result;
}


推荐答案

浮点表达式的值为int,数据只是在赋值时被截断(但在表达式被计算之后)。

Since you're assigning the value of a float expression to an int, the data simply gets truncated upon assignment (but after the expression is evaluated).

这篇关于编译器对我的类型转换方法做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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