初始化“float"时,强制转换为“float"和添加“f"作为后缀有什么区别? [英] What is the difference between casting to `float` and adding `f` as a suffix when initializing a `float`?
本文介绍了初始化“float"时,强制转换为“float"和添加“f"作为后缀有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么区别
float f = (float) 99.32 ;
和
float f = 99.32f ;
它们都编译并成功运行.
Both of them compiled and ran successfully.
推荐答案
float f = 99.32f ;
那是一个 float
字面量,意思是一个 float 变量直接赋值给一个 float
值.
That is a float
literal, which means a float variable being assigned with a float
value directly.
float f = (float) 99.32 ;
这是一个 float
变量,它被分配了一个 double
值,该值在分配之前被转换为 float
.
That is a float
variable that is assigned a double
value that is cast to float
before being assigned.
这篇关于初始化“float"时,强制转换为“float"和添加“f"作为后缀有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文