Cannot cast variable type to its pointer type (e.g. int to int*). I guess it's a bad thing to do, but why isn't it possible?
<p><code>&lt;what_I_have_tried&gt;</code></p>

<ol>
<li>Looking at the suggestion list.</li>
<li>In Google: <em>how not to use pointers c</em> (idea: is it an idea to summarize all ways pointer declaration, assignment and use could go wrong in a SO question? I know it would be helpful for me, since I'm trying to understand pointers by searching edge cases in order to see if I understand all the concepts)</li>
<li>In Google: <em>errors from pointers c</em></li>
<li>In SO: <em>int to int*</em></li>
<li>Read a bunch of general stuff on pointers. I view <code>*</code> as a dereference operator. I used to view <code>*</code> as a sort of 'second variable' and saw a pointer as a 'macro variable' (e.g. <code>*a</code> and b are parts of <code>a</code> 'macro variable'). This is completely wrong. Now I view <code>int *a</code> as one variable (just like <code>int b</code>), which is accessed by typing <code>a</code> and <code>*</code> is an operator. Interestingly, one small idea I have then is that you cannot dereference a pointer at the moment you declare it, since the <code>*</code> is then part of the type declaration (e.g. <code>int *p</code> is a pointer declaration. Likewise, <code>int* *q</code> -- confusing syntax is on purpose -- is a pointer to pointer declaration, i.e. you cannot use the dereference operator since the <code>*</code> is parsed as part of the type).</li>
</ol>

<p><code>&lt;/what_I_have_tried&gt;</code></p>

<p>Here is the question. Note, I'm using edge cases to understand a concept, not to promote bad software practices. I'm testing to see to what point I understand dereferencing/referencing and pointers in general, hence I try to let C do things it probably doesn't want to do normally. Considering the following program. It's a pure beauty ;)</p>

<pre><code>#include "stdio.h"

int main(void) {
    int a = 0;
    int b = 5;
    printf("a: %d, b: %d\n", a, b);
    a = &amp;b; //bad intentions! Lets see what happens, we can cast right?
    printf("a: %d, b: %d, &amp;b: %d\n", a, b, &amp;b);
    printf("*a: %d", (*((int *)a)));

    return 0;
}
</code></pre>

<p>The output is:</p>

<pre><code>a: 0, b: 5
a: 1508416372, b: 5, &amp;b: 1508416372
Segmentation fault: 11
</code></pre>

<p>My thoughts for the first 30 minutes. "How can this happen?! They have the SAME MEMORY ADDRESS!!" Excuse my screaming, but this looks rather frustrating. Before going to SO, I opened up GDB breaking at the final <code>printf</code>. Compilation settings are: <code>gcc -g -O0 test.c -o a</code>. The relevant GDB output is:</p>

<pre><code>(gdb) p/x a
$3 = 0x5fbffb34
(gdb) p/x &amp;b
$4 = 0x7fff5fbffb34
</code></pre>

<p>Wait what? The function <code>printf</code> is not showing me the full output. I did not expect this.</p>

<p>So... to test the concept again I added 0x7fff to a. It didn't work, because adding 0x7fff to 0x5fbffb34 is not the same as appending it. </p>

<p>Now that I think about it, I think I have the answer. I'm running a 64 bit machine and I've been assuming that <code>int *</code> and <code>int</code> get the same amount of bytes allocated but it could be that it doesn't work because <code>int *</code> gets 4 bytes (32 bits) or 8 bytes (64 bits) allocated -- I'm running 64 bits on Mac OSX. Is this why it doesn't work?</p>

<p>I'm stopping here, else I'm breaking the Q&amp;A format I suppose. I was writing this question while debugging, so the chronology is quite preserved. I'm now going to see if I can append 0x7fff somehow since I don't have a 32-bit machine to test on.</p>

<p><strong>Edit and conclusion</strong> (warning, it might be too in-depth for the earliest beginners):</p>

<p>With the answer in mind, I can conclude the following. In <em>GCC</em> <strong>pointers store memory addresses</strong>. From a non-compiler but practical perspective pointers store references to objects and functions (and in GCC that gets translated to a memory address) -- as a programmer this is as far as I need to go. I read from <a href="https://stackoverflow.com/questions/15151377/what-exactly-is-a-c-pointer-if-not-a-memory-address">this question</a> that the C standard views this even a bit more broadly.</p>

<p>I can also conclude that, conceptually, you can dereference whatever you want. Dereferencing, from a conceptual perspective, always works or is at the very least attempted to be executed. In the code of my question <code>0x5fbffb34</code> was attempted to be dereferenced or was even dereferenced. However, a conceptual perspective is not a practical one. In the real world, the operating system does some checks when the dereference is attempted or when the value is returned. Hence, it interfered and kills the program since the memory address was not in the boundaries of my program (that's my guess at least). </p>

<p>Another conclusion is that people who draw boxes with arrows when they declare and initialize a pointer are wrong. In my opinion, the arrow should only be drawn when a pointer is dereferenced. This is because the arrow is part of dereferencing a value from a memory address. A pointer (and its related type, e.g. <code>int *</code>) only helps and guides to get defined behaviour. It's kind of like when you dereference a value from a pointer variable (e.g. <code>int b = 0; int *a = &amp;b; int c = *a;</code>), then you get a 'safe(ish) arrow'. When you dereference a value from a non-pointer variable, then you get a 'deadly(ish) arrow' as can be seen in my program.</p>