title: how to change value in a specific memory address?
body: <p>I'm new to c programming. There is a use case: I need to change value in a specific memory address.</p>
  <pre><code>int main(){
  
      int *p;
      p = 0x111;
      *p = 100;
      return 0; 
  }
  </code></pre>
  <p>However, I cannot compile the above code. It shows the following problem.</p>
  <pre><code>test.c:10:7: warning: incompatible integer to pointer conversion assigning to 'int *' from 'int' [-Wint-conversion]
      p = 0x111;
        ^ ~~~~~
  1 warning generated.
  </code></pre>
  <p>I tried casting like following:</p>
  <pre><code>int main(){
  
      int *p;
      p = (int *) 0x111;
      *p = 100;
      return 0; 
  }
  </code></pre>
  <p>It can compile, however, when I run it, it shows <code>segmentation fault</code>.</p>
  <p>My Question:</p>
  <ol>
  <li><p>Is there a way that I can forcedly compile and run this code? I know there is wild pointer problem. However, it's a common use case to manipulate memory. For example, when I play a local game. Somehow, I know the specific memory address of my player's health point when the game is running, e.g. address = 0x123. How to just change the value in 0x123?</p>
  </li>
  <li><p>If I cannot use above way to manipulate value in any specific memory address, is there other standard way to realize my use case?</p>
  </li>
  </ol>
  <p>PS:
  By the way, I found the example way to realize my use case.</p>
  <p>You can refer to the source code: <a href="https://github.com/haseeb-heaven/GTLibc/" rel="nofollow noreferrer">https://github.com/haseeb-heaven/GTLibc/</a></p>
  <p><a href="https://stackoverflow.com/questions/2926739/how-do-game-trainers-change-an-address-in-memory-thats-dynamic">How do game trainers change an address in memory that&#39;s dynamic?</a></p>
  <p><a href="https://www.youtube.com/watch?v=cRCnN987gd8&amp;ab_channel=HaseebMir" rel="nofollow noreferrer">https://www.youtube.com/watch?v=cRCnN987gd8&amp;ab_channel=HaseebMir</a></p>