简体   繁体   English

变量的C ++ Borland地址

[英]C++ Borland address of the variable

int main(int argc, char* argv[])
{
        int *pInt;
        int iParam = 423425;
        pInt = &iParam;
        std::cout<<&pInt<<std::endl;
        system("pause");
        return 0;
}

Why am i getting address like 1250008 and not like 0x00000 ? 为什么我得到的地址像1250008而不是0x00000?

It returns you the addresss where pInt is located in virtual memory. 它会返回给您pInt在虚拟内存中的地址。
It can be any address. 它可以是任何地址。 The compiler is free to place an pointer at any address in the address space allocated to an process. 编译器可以自由地将指针放置在分配给进程的地址空间中的任何地址上。

If you mean to get the address in hex and not decimal, you need to do use I/O Manipulator like this: 如果要获取hex而不是十进制的地址,则需要使用I / O操纵器,如下所示:

std::cout << hex << &pInt << std::endl; 

If you execute the statement printf("%x", iParam), The value stored in iParam is converted into hex and printed but it will not be started with 0X. 如果执行语句printf(“%x”,iParam),则iParam中存储的值将转换为十六进制并进行打印,但不会以0X开头。 The same scenario is also in case of printing address. 在打印地址的情况下也是如此。 It does not starts with 0X. 它不是以0X开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM