注册 登录
编程论坛 C++教室

十六进制的地址为什么要00开头而不是0x?

maxlea 发布于 2007-01-25 17:32, 3435 次点击


#include <iostream>
using namespace std;
int main()
{
    int a=10;
    double b=10.11;
    cout << \"The value of a is \" << a << \" and the address of a is \" << &a << endl ;
    cout << \"The value of b is \" << b << \" and the address of b is \" << &b << endl ;
    return 0;
}

6 回复
#2
一二三四五2007-01-25 19:11
不是十六进制,当然就不是0x开头了
#3
tyc6112007-01-25 23:15

你程序输出会00头?深表怀疑^_^

#4
醉生梦死2007-08-27 13:26
我试过,是以ox头的
#5
valentineyzq2007-08-29 22:43
我试过了,是以00开头的。我的机子上的16进制都是00开头。这是系统的差别吧?我觉得不碍事。
#6
天使梦魔2007-08-30 08:46
一样的,表示方法不同。
你多用用十六进制文本编辑器就知道了。
00就代表0*
如果要看整数型就用强制转换看看一不一样。
cout << "The value of a is " << a << " and the address of a is " << int(&a) << endl ;
cout << "The value of b is " << b << " and the address of b is " << int(&b) << endl ;
#7
HJin2007-08-30 09:28

#include <iostream>
using namespace std;
int main()
{
int a=10;
double b=10.11;

cout << "The value of a is " << a << " and the address of a is "<<hex<<showbase<< (int)(&a) << endl ;
cout << "The value of b is " << b << " and the address of b is " << &b << endl ;


return 0;
}

/** Output from VC 2005:

The value of a is 10 and the address of a is 0x12ff68
The value of b is 10.11 and the address of b is 0012FF6C
Press any key to continue . . .

Suggestion: if you want to show the base of a number, you may want to use
the io manipulators showbase or noshowbase, etc.

*/

1