类型转换
#include<iostream>
using namespace std;
int main() {
//测试表达式类型的转换
int n = 100, m;
double x = 3.4157, y;
cout << "n*x = " << n * x << endl;
//赋值类型转换
m = x;
y = n;
cout << "m = " << m << endl;
cout << "n = " << n << endl;
//强制类型转换
cout << "int(x) = " << int(x) << endl;
cout << "(int)x = " << (int)x << endl;
cout << "int(1.7342+x) = " << int(1.7342 + x) << endl;
cout << "(int)1.7342+x = " << (int)1.7342 + x << endl;
cout << "double(100)=" << double(100) << endl;
return 0;
}

浙公网安备 33010602011771号