那么,是否可以像这样在 C++ 中创建一个指针,并将其打印出来:
#include <iostream>
int main() {
int* ptr = new int;
(*ptr) = 3;
std::cout << ptr << '\n';
}
Run Code Online (Sandbox Code Playgroud)
然后运行它,复制 ptr 的值,并在另一个程序中,当它正在运行时,执行以下操作:
#include <iostream>
#include <cstring>
int main() {
long long pointer;
std::cin >> pointer;
int* ptr = nullptr;
std::memcpy(&ptr, &pointer, sizeof(pointer));
std::cout << *ptr << '\n';
}
Run Code Online (Sandbox Code Playgroud)
并打印出 3 个?有可能吗,或者如果没有,那究竟是为什么?