如果知道变量地址,如何在C ++中检索变量值 [英] How to retrieving variable value in C++ if you know the variable address

查看:72
本文介绍了如果知道变量地址,如何在C ++中检索变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

我最近开始用 C ++ 进行编码,并且遇到了一个我找不到答案的问题,所以我想也许其他人可能会知道答案.

I have recently started to code in C++ and have come across a problem to which I was unable to find the answer, so I thought maybe somebody else might know the answer.

如果您知道变量地址,是否可以从另一个程序中检索变量值?想象一下,我在程序中显示了一个内存地址,例如: 0x7fff5fbff758 并且我希望(在与第一个程序无关的我自己的程序中)将 存储在该内存地址中.

Is it possible to retrieve a variable value from another program if you know a variable address? Imagine that I have a memory address displayed in a program, something like: 0x7fff5fbff758 and I would like (in my own program which is not related to the first one) to get the value stored in that memory address.

有可能吗?如果是这样,有人可以向我解释一下. 预先谢谢你.

Is that possible? If so, could somebody please explain me how. Thank you in advance.

推荐答案

在当今的操作系统上,程序处理虚拟地址,而不是物理地址.很快,一个程序的特定地址不会指向其他程序的相同物理位置.

On today operating systems, the programs handle virtual addresses, not physical ones. Shortly, a specific address for one programs will not point to the same physical location for other programs.

例如,要在现代操作系统上执行所需的操作,可以设置共享内存位置.

To do what you want on modern operating systems, you can, for instance, set up a shared memory location.

但是有很多更简单的方法可以将值从一个程序传递到另一个程序.

But there is a lot of easier way to pass a value from one program to another.

如果您只是出于好奇而想知道这是一个好问题,可以看看什么是虚拟内存".

If you are just wondering that out of curiosity, that's a good question, you can look at what "virtual memory" is.

这篇关于如果知道变量地址,如何在C ++中检索变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆