什么是(C语言)初始化时,0.0的意义是什么? [英] What is the significance of 0.0f when initializing (in C)?

查看:211
本文介绍了什么是(C语言)初始化时,0.0的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过code,人们初始化这样的浮点型变量:

I've seen code where people initialize float variables like this:

float num = 0.0f;

有没有这之间有显著差异,只是在做下面的下面?

Is there a significant difference between this and just doing the following below?

float num = 0; 

谢谢..:)

推荐答案

浮动X = 0 有从int隐式类型转换浮动。结果
浮动X = 0.0 没有这样的类型转换。结果
浮X = 0.0 具有双重的隐式类型转换浮动。

float x = 0 has an implicit typecast from int to float.
float x = 0.0f does not have such a typecast.
float x = 0.0 has an implicit typecast from double to float.

根据不同的编译器,隐式类型转换可能需要编译器生成额外的code。

Depending on the compiler, implicit typecast can require the compiler to generate extra code.

这篇关于什么是(C语言)初始化时,0.0的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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