小编tua*_*nhN的帖子

无法在C++中打印指针的地址

我是c++新手。我写了这个程序。

#include <iostream>

using namespace std;

int main(void) {
    int x=24;
    char y='A';
    char* pchar=&y;
    int* pint=&x;

    cout <<"pchar= "<<hex<<&pchar<<endl;
    cout <<"pint = "<<hex<<&pint<<endl;
    cout <<endl;
    cout <<"pchar= "<<hex<<pchar<<endl;
    cout <<"pint = "<<hex<<pint<<endl;

    pchar=NULL;
    pint=NULL;
    getchar();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

及其结果 https://www.dropbox.com/s/wzxp1tkuqgw5p3g/Screenshot%202014-02-18%2022.52.29.png

你能帮我理解为什么我不能在没有 的情况下打印变量的地址吗&?我认为pchar已经是 的地址y

谢谢

c++

2
推荐指数
1
解决办法
4218
查看次数

标签 统计

c++ ×1