title: How do you know the exact address of a variable?
body: <p>So I'm looking through my C programming text book and I see this code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int j, k;
  int *ptr;
  
  int main(void)
  {
      j = 1;
      k = 2;
      ptr = &amp;k;
      printf("\n");
      printf("j has the value %d and is stored at %p\n", j, (void *)&amp;j);
      printf("k has the value %d and is stored at %p\n", k, (void *)&amp;k);
      printf("ptr has the value %p and is stored at %p\n", (void *)ptr, (void *)&amp;ptr);
      printf("The value of the integer pointed to by ptr is %d\n", *ptr);
  
      return 0;
  }
  </code></pre>
  
  <p>I ran it and the output was:</p>
  
  <blockquote>
    <p>j has the value 1 and is stored at 0x4030e0<br><br>
    k has the value 2 and is stored at 0x403100<p>
    ptr has the value 0x403100 and is stored at 0x4030f0<p>
    The value of the integer pointed to by ptr is 2</p>
  </blockquote>
  
  <p>My question is if I had not ran this through a compiler, how would you know the address to those variables by just looking at this code? I'm just not sure how to get the actual address of a variable. Thanks!</p>