[英]why does this c++ static cast code produce and int not a double
Im new to C++ and i'm not sure why the output for this code is 8 and not 8.25? 我是C ++的新手,我不确定为什么此代码的输出是8而不是8.25?
can someone explain why this code outputs an int not a double? 有人可以解释为什么此代码输出int而不是double吗?
Thanks :) 谢谢 :)
#include "stdafx.h"
#include <iostream>
int main()
{
double x = 8.25;
int y;
y = x;
double z = static_cast<double>(y);
std::cout << z << std::endl;
return 0;
}
The data is converted to the integer 8
in the statement y = x
. 数据在语句
y = x
转换为整数8
。
A static_cast
cannot recover the lost ".25" after throwing it away by converting to int
. 通过将
static_cast
转换为int
来丢掉丢失的“ .25”后,它无法恢复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.