【发布时间】:2014-09-12 05:16:49
【问题描述】:
考虑以下代码:
char char_a = 'A';
int int_b = 34;
char* p_a = &char_a;
int* p_b = &int_b;
cout<<"Value of int_b is (*p_b) :"<< *p_b<<endl;
cout<<"Value of &int_b is (p_b) :"<< p_b<<endl;
cout<<"Value of char_a is (*p_a) :"<< *p_a<<endl;
cout<<"Value of &char_a is (p_a) :"<< p_a<<endl;
当我运行它时,输出是:
那么为什么它在字符指针的情况下不像整数指针那样显示地址呢?
【问题讨论】:
-
你在另一台电脑上试过这个代码吗??
-
printf("%p\n", p_a); -
是的,我已经检查过了。它在那里给出相同的符号。
-
你需要
cout<<"Value of &char_a is (p_a) :"<< reinterpret_cast<void *>(p_a) <<endl;(你也可以使用static_cast)