#include<iostream>
using namespace std;
int main()
{float x;int i;
x=3.6;i=(int)x;
cout<<"x="<<x<<",i="<<i<<endl;
return 0;}
warning C4305: '=' : truncation from 'const double' to 'float'
在 C 语言中,如果不指定数据类型,那么小数常量会被认为是 double 类型的。 因此在初始化中 x = 3.6; 这一句,x 是 float 类型的,但是 3.6 是 double 类型的,由于它是常量,所以编译器称为 const double。double 是不能隐式转换为 float 的。
可以这样写x=3.6f;