从内存地址获取值
Get value from memory address
我有一个int*
变量,用于存储内存地址的示例地址0x28c1150
。
我想知道,地址存储了什么值。
编辑:
struct list {
int value;
list *next;
list *head = NULL;
void push(int n);
void select();
void pop();
void top();
};
void list::push(int value) {
list *temp = new list;
temp->value = value;
temp->next = head;
head = temp;
}
void list::top(){
list * temp = new list;
cout << head;
}
我想打印列表的顶部
如果您的变量为 list*
:
list* variable = new list;
variable->top();
...但是请注意,您当前的top()
功能会泄漏内存,因为您每次被称为新列表,而您只是忘记了它。改用此方法:
int list::top(){
return head->value;
}
std::cout << variable->top() << "n";
您必须取消指针:
template<class T>
void print_value_at(T* pointer) {
T& value = *pointer; //get value in pointer
// print value
std::cout << value <<std::endl;
}
如果指针无效,则必须将其施放为最初的任何类型:
int x = 10;
// get void pointer to x
void* x_pointer_as_void = (void*)&x;
// convert it back to a pointer to an int:
int* x_pointer = (int*)x_pointer_as_void;
这里(基于问题的当前版本)
cout << head->value;
相关文章:
- 如何在C++中获取该对象的类声明中对象的地址?
- 如何使用 Boost Asio 在 Android 上获取我的本地 udp IP 地址?
- 如何获取C++字符数据类型的地址
- 如果 const 不分配内存,为什么我可以获取 const 的地址?
- 如何在 c++ stl 中获取列表中被推回的元素的地址,在常量时间内?
- 是否可以在C++中获取 CHAR 的有效十六进制地址?
- 动态获取 esp32 的 mac 地址并在以太网库中使用它.
- 获取 R 数据帧的内存地址
- 获取通用/前向引用地址有什么意义?
- 获取函数的地址?
- 获取指针的地址会为其分配一个值
- Assimp 库错误:获取打包成员的地址
- 有没有可以直接获取地址的右值?
- 在char*类型上使用static_cast获取地址,并获得24位和48位地址
- 从套接字获取地址系列.Linux
- 为什么在解析 main() 参数时获取地址值
- 获取地址在数组2d中的位置
- 在c++中获取地址的内容
- 如何在c#函数中从委托中获取地址
- 无法获取地址 (wcsstr) - 未定义的变量