我是编程新手。我有一个问题,我自己找不到可以理解的答案。我想用 C++ 和 C 找到指针的地址,但是两个结果不同,尽管它们有一些相似的数字。他们还是同一个地址吗?
adress of g is :0018F9C4
address of g is: 0018F9D3
这是我的代码:
#include<iostream>
#include<stdio.h>
void main()
{
char g = 'z';
char*p;
p = &g;
std::cout << "adress of g is :" << &p;
printf("\naddress of g is: %p", p);
}
最佳答案
这一行显示的地址 p
std::cout << "address of p is :" << &p;
这一行显示地址在p
,即地址of g
printf("\naddress of g is: %p", p);
有不同的结果是正常的。
尝试
std::cout << "address of g is :" << static_cast<void*>(p);
printf("\naddress of g is: %p", p);
关于c++ - 指针地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35864098/