代码:
int a;
cin>>a;
cout<<a<<endl;
Run Code Online (Sandbox Code Playgroud)
然后我使用g++ test.cpp并运行它。然后我向变量 a 输入字母“b”。输出为0。
但是,当我测试其他代码时:
cout<<int('b')<<endl; // output: 98
Run Code Online (Sandbox Code Playgroud)
为什么?有什么不同?
在我的电脑上.当我测试代码时:
int main()
{
int i=123;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
运用
g++ -g test.cpp -o test
Run Code Online (Sandbox Code Playgroud)
我进入时发现:
print &i output: 0x7fffffffe18c
print sizeof(&i) output: 8
Run Code Online (Sandbox Code Playgroud)
我很困惑,我的地址是6字节,为什么sizeof(&i)==8?非常感谢