类型转换

#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;
}

posted @ 2021-07-01 14:57  江南王小帅  阅读(17)  评论(0)    收藏  举报