为什么没有显示字符数据的地址?class Address {
int i ;
char b;
string c;
public:
void showMap ( void ) ;};void Address :: showMap ( void ) {
cout << "address of int :" << &i << endl ;
cout << "address of char :" << &b << endl ;
cout << "address of string :" << &c << endl ;}产出如下: address of int : something
address of char : // nothing, blank area, that is nothing displayed
address of string : something为什么?另一件有趣的事情是:如果int、char、string是公开的,那么输出是 ... int : something
... char :
... string : something_2something_2 - something总是等于8。为什么?(不是9)
3 回答
烙印99
TA贡献1829条经验 获得超13个赞
char *
. operator<<
cout << "address of char :" << (void *) &b << endl
static_cast
cout << "address of char :" << static_cast<void *>(&b) << endl;
- 3 回答
- 0 关注
- 441 浏览
添加回答
举报
0/150
提交
取消