我想将char
值转换为int
. 我正在玩以下代码片段:
#include <iostream>
using namespace std;
int main() {
char a = 'A';
int i = (int)a;
//cout<<i<<endl; OUTPUT is 65 (True)
char b = '18';
int j = b;
//cout<<j<<endl; OUTPUT is 56 (HOW?)
char c = 18;
int k = c;
//cout<<c<<endl; OUTPUT is empty
//cout<<k<<endl; OUTPUT is 18 (Is this a valid conversion?)
return 0;
}
我想要第三次转换,我得到了正确的输出,即18
. 但这是有效的转换吗?谁能解释一下上述输出及其策略?