15 lines
361 B
C++
15 lines
361 B
C++
|
#include <iostream>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
char c = 'a'; // 1B
|
||
|
int m = 2; // 4B
|
||
|
// 小字节转大字节, 会自动转换
|
||
|
m += c; // 先将c转换为int,再相加
|
||
|
cout << "m = " << m << endl;
|
||
|
// 大字节转小字节,会丢失精度,需要强制类型转换
|
||
|
cout << "m to char is " << (char)m << endl;
|
||
|
return 0;
|
||
|
}
|