我在以下代码段中打印变量的地址。
int int1=3;
char ch1='f';
printf("address int1 %llX\n",&int1);
printf("address ch1 %llX\n",&ch1);
cout<<"address int1 "<<&int1<<endl;
cout<<"address ch1 "<<&ch1<<endl;
这是输出:
address int1 7FFF47D7C0F0
address ch1 7FFF47D7C0E8
address int1 0x7fff47d7c0f0
address ch1 f@
我的问题是为什么 cout 在此示例中打印字符的内容而不是其地址?但是, printf 显示如上所示的地址。此外,以下还正确显示地址:
cout<<"address ch1 "<<(void*)&ch1<<endl;