title: Casting char pointer to int pointer - buffer error 10
body: <p>In this <a href="https://stackoverflow.com/a/430414/1507139">answer</a>, the author discussed how it was possible to cast pointers in C. I wanted to try this out and constructed this code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void) {
      char *c;
      *c = 10;
      int i = *(int*)(c);
      printf("%d", i);
      return 1;
  }
  </code></pre>
  
  <p>This compiles (with a warning) and when I execute the binary it just outputs <code>bus error: 10</code>. I understand that a char is a smaller size than an int. I also understand from this <a href="https://stackoverflow.com/questions/212466/what-is-a-bus-error">post</a> that I should expect this error. But I'd really appreciate if someone could clarify on what is going on here. In addition, I'd like to know if there is a correct way to cast the pointers and dereference the int pointer to get 10 (in this example). Thanks!</p>
  
  <p>EDIT: To clarify my intent, if you are worried, I'm just trying to come up with a "working" example of pointer casting. This is just to show that this is allowed and <em>might</em> work in C.</p>