C ++差值在0和0.0之间 [英] C++ difference between 0 and 0.0

查看:213
本文介绍了C ++差值在0和0.0之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中0和0.0之间有区别吗?

Is there a difference between 0 and 0.0 in C++? Which should you use for initializing a double?

感谢

推荐答案

文字 0 被视为 int 文字;文字 0.0 是一个 double 文字。当分配给 double 时,这两个都会起作用(因为 int 可以转换为扩展转换);但是,将 0.0 转换为 int 是一种缩小的转换,必须明确完成;即(int)0.0

A literal 0 is considered to be an int literal; literal 0.0 is a double literal. When assigning to a double, either will work (since the int can be cast in a widening conversion); however, casting 0.0 to an int is a narrowing conversion, and must be done explicitly; i.e. (int)0.0.

这篇关于C ++差值在0和0.0之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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