title: Dereferencing this pointer gives me -46, but I am not sure why
body: <p>This is a program I ran:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int y = 1234;
      char *p = &amp;y;
      int *j = &amp;y;
      printf("%d %d\n", *p, *j);
  }
  </code></pre>
  
  <p>I am slightly confused about the output. What I'm seeing is:</p>
  
  <pre><code>-46 1234
  </code></pre>
  
  <p>I wrote this program as an experiment and wasn't sure what it was going to output. I was expecting possibly one byte from <code>y</code>.</p>
  
  <p>What is happening "behind-the-scenes" here? How does dereferencing <code>p</code> give me <code>-46</code>?</p>
  
  <p>As pointed out by others, I had to do explicit casting to not cause UB. I am not changing that line from <code>char *p = &amp;y;</code> to <code>char *p = (char *)&amp;y;</code> so that I am not invalidating the answers below.</p>
  
  <p>This program is not causing any UB behaviour as pointed <a href="https://stackoverflow.com/questions/35496014/type-casting-char-pointer-to-integer-pointer?rq=1">here</a>.</p>