<i id='Cbz8e'><tr id='Cbz8e'><dt id='Cbz8e'><q id='Cbz8e'><span id='Cbz8e'><b id='Cbz8e'><form id='Cbz8e'><ins id='Cbz8e'></ins><ul id='Cbz8e'></ul><sub id='Cbz8e'></sub></form><legend id='Cbz8e'></legend><bdo id='Cbz8e'><pre id='Cbz8e'><center id='Cbz8e'></center></pre></bdo></b><th id='Cbz8e'></th></span></q></dt></tr></i><div id='Cbz8e'><tfoot id='Cbz8e'></tfoot><dl id='Cbz8e'><fieldset id='Cbz8e'></fieldset></dl></div>
  • <small id='Cbz8e'></small><noframes id='Cbz8e'>

      <bdo id='Cbz8e'></bdo><ul id='Cbz8e'></ul>

        <legend id='Cbz8e'><style id='Cbz8e'><dir id='Cbz8e'><q id='Cbz8e'></q></dir></style></legend><tfoot id='Cbz8e'></tfoot>

        C++ - 获取特定内存地址的值

        时间:2023-09-15
        <i id='MTmFV'><tr id='MTmFV'><dt id='MTmFV'><q id='MTmFV'><span id='MTmFV'><b id='MTmFV'><form id='MTmFV'><ins id='MTmFV'></ins><ul id='MTmFV'></ul><sub id='MTmFV'></sub></form><legend id='MTmFV'></legend><bdo id='MTmFV'><pre id='MTmFV'><center id='MTmFV'></center></pre></bdo></b><th id='MTmFV'></th></span></q></dt></tr></i><div id='MTmFV'><tfoot id='MTmFV'></tfoot><dl id='MTmFV'><fieldset id='MTmFV'></fieldset></dl></div>

                • <bdo id='MTmFV'></bdo><ul id='MTmFV'></ul>
                    <tbody id='MTmFV'></tbody>

                  <tfoot id='MTmFV'></tfoot>

                • <small id='MTmFV'></small><noframes id='MTmFV'>

                  <legend id='MTmFV'><style id='MTmFV'><dir id='MTmFV'><q id='MTmFV'></q></dir></style></legend>

                  本文介绍了C++ - 获取特定内存地址的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道是否可以做这样的事情:

                  I was wondering whether it is possible to do something like this:

                  unsigned int address = 0x0001FBDC; // Random address :P
                  int value = *address; // Dereference of address
                  

                  意思是,是否可以获取内存中特定地址的值?

                  Meaning, is it possible to get the value of a particular address in memory ?

                  谢谢

                  推荐答案

                  你可以而且应该这样写:

                  You can and should write it like this:

                  #include <cstdint>
                  
                  uintptr_t p = 0x0001FBDC;
                  int value = *reinterpret_cast<int *>(p);
                  

                  请注意,除非有某种保证 p 指向整数,否则这是未定义的行为.如果您尝试访问它不希望您访问的地址,则标准操作系统将终止您的进程.但是,这可能是独立程序中的常见模式.

                  Note that unless there is some guarantee that p points to an integer, this is undefined behaviour. A standard operating system will kill your process if you try to access an address that it didn't expect you to address. However, this may be a common pattern in free-standing programs.

                  (早期版本的 C++ 应该说 #include intptr_t.)

                  (Earlier versions of C++ should say #include <stdint.h> and intptr_t.)

                  这篇关于C++ - 获取特定内存地址的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C++结构对齐问题 下一篇:在 Amazon EC2 上安装测试应用程序

                  相关文章

                  最新文章

                  1. <small id='uIxCE'></small><noframes id='uIxCE'>

                  2. <tfoot id='uIxCE'></tfoot>
                  3. <i id='uIxCE'><tr id='uIxCE'><dt id='uIxCE'><q id='uIxCE'><span id='uIxCE'><b id='uIxCE'><form id='uIxCE'><ins id='uIxCE'></ins><ul id='uIxCE'></ul><sub id='uIxCE'></sub></form><legend id='uIxCE'></legend><bdo id='uIxCE'><pre id='uIxCE'><center id='uIxCE'></center></pre></bdo></b><th id='uIxCE'></th></span></q></dt></tr></i><div id='uIxCE'><tfoot id='uIxCE'></tfoot><dl id='uIxCE'><fieldset id='uIxCE'></fieldset></dl></div>
                    <legend id='uIxCE'><style id='uIxCE'><dir id='uIxCE'><q id='uIxCE'></q></dir></style></legend>
                      <bdo id='uIxCE'></bdo><ul id='uIxCE'></ul>