title: How can I get the address of a struct in C?
body: <p>I'm an absolute newbie to C so this may be a dumb question, warning! </p>
  
  <p>It's inspired by the extra credit section of <a href="http://c.learncodethehardway.org/book/learn-c-the-hard-waych17.html" rel="noreferrer">Exercise 16</a> in Learn C the Hard Way, if anyone is wondering about context.</p>
  
  <p>Assuming these imports:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;stdlib.h&gt;
  </code></pre>
  
  <p>And given a simple struct like this:</p>
  
  <pre><code>struct Point {
      int x;
      int y;
  };
  </code></pre>
  
  <p>If I create an instance of it on the heap:</p>
  
  <pre><code>struct Point *center = malloc(sizeof(Point));
  assert(center != NULL);
  center-&gt;x = 0;
  center-&gt;y = 0;
  </code></pre>
  
  <p>Then I know I can print the location of the struct in memory like this:</p>
  
  <pre><code>printf("Location: %p\n", (void*)center);
  </code></pre>
  
  <p>But what if I create it on the stack?</p>
  
  <pre><code>struct Point offCenter = { 1, 1 };
  </code></pre>
  
  <p>Values sitting in the stack still have a location in memory somewhere. So how do I get at that information? Do I need to create a pointer to my new on-the-stack-struct and then use that?</p>
  
  <p><strong>EDIT:</strong> Whoops, guess that was a bit of an obvious one. Thanks to Daniel and Clifford! For completeness here's the print example using <code>&amp;</code>:</p>
  
  <pre><code>printf("Location: %p\n", (void*)&amp;center);
  </code></pre>