在C++中,小数默认为双精度
隐式类型转换:当需要进行算术运算时,编译器会自动将整数类型转换为更高精度的浮点数类型。
#include <iostream>
using namespace std;
int main() {
int num = 5; // 定义一个整数变量num并初始化为5
double result = num + 3.0; // 将整数与双精度浮点数相加,结果存放到result变量中
cout << "Result: " << result << endl; // 输出结果
return 0;
}