title: Why can't I memcpy an int to a char[] without getting the address of the int?
body: <p>This might be a duplicate, but I haven't found any other question dealing with my exact situation (yet).</p>
  
  <p>Here's what I'm trying to do:</p>
  
  <pre><code>int n = 12;
  char s[sizeof(n)];
  memcpy(s, (char *)n, sizeof(n));
  printf("%d", s);
  </code></pre>
  
  <p>Basically, I want to copy <code>n</code> into <code>s</code> without having to get the address of <code>n</code>. When I run this, it gives me a segmentation fault. This, however, works:</p>
  
  <pre><code>printf("%d", (char *)n);
  </code></pre>
  
  <p>So I know that the problem is in the memcpy call. Why can't I memcpy an int into a char[] like this?</p>