When you think of pointers, it helps to draw diagrams . A pointer is an arrow pointing to an address in memory, with a label indicating the type of value. The address indicates where to look, and the type indicates what to do. Hovering the cursor changes the mark on the arrow, but not where the arrow is indicated.
d in main is a pointer to c , which is of type char . A char is one byte of memory, so when d dereferenced, you get a value in that byte of memory. In the diagram below, each cell represents one byte.
-+----+----+----+----+----+----+- | | c | | | | | -+----+----+----+----+----+----+- ^~~~ | char d
When you press d on int* you say that d really points to the value of int . On most systems today, int takes 4 bytes.
-+----+----+----+----+----+----+- | | c | ?β | ?β | ?β | | -+----+----+----+----+----+----+- ^~~~~~~~~~~~~~~~~~~ | int (int*)d
When you cast (int*)d , you get a value that is determined from these four bytes of memory. The value you get depends on what is in these cells marked with ? , and how int displayed in memory.
The PC is little-endian , which means that the int value is calculated this way (assuming it covers 4 bytes): * ((int*)d) == c + ?β * 2βΈ + ?β * 2ΒΉβΆ + ?β * 2Β²β΄ . Thus, you will see that while the value is garbage, if you print in hexadecimal format ( printf("%x\n", *n) ), the last two digits will always be 35 (this is the value of the character '5' ).
Some other systems are large and arrange bytes in the other direction: * ((int*)d) == c * 2Β²β΄ + ?β * 2ΒΉβΆ + ?β * 2βΈ + ?β . On these systems, you will find that the value always starts at 35 when printing in hexadecimal format. Some systems have an int size that differs from 4 bytes. Rare few systems arrange int in different ways, but you are unlikely to meet them.
Depending on your compiler and operating system, you may find that each time the program starts, the value is different or it is always the same, but it changes when you make even small changes in the source code.
On some systems, the int value must be stored in an address that is a multiple of 4 (or 2 or 8). This is called alignment . Depending on whether the address c correctly aligned or not, the program may fail.
Unlike your program, this is what happens when you have an int value and hover over it.
int x = 42; int *p = &x;
-+----+----+----+----+----+----+- | | x | | -+----+----+----+----+----+----+- ^~~~~~~~~~~~~~~~~~~ | int p
Pointer p points to an int value. The label on the arrow correctly describes what is in the memory cell, so there are no surprises when dereferencing.