TL;DR - Read about endianness. Most likely, you're on a little-endian system. You can check that yourself by running a short program.
Regarding the use of character pointer to point to another type, and use that to access the value, quoting C11
, chapter 6.3.2.3/P7
...When a pointer to an object is converted to a pointer to a character type, the result points to the lowest addressed byte of the object. Successive increments of the result, up to the size of the object, yield pointers to the remaining bytes of the object.
So, if you're on a little endian system, the values are stored like
+----------+-----------+-----------+-----------+
| | | | |
| 12 | E0 | CD | AB |
| | | | |
+----------+-----------+-----------+-----------+
1000 1001 1002 1003 1004
^
|
q
Assuming, the starting address is 1000. So, q
initially points to address 1000, and with every increment, it moves 1 byte, and when read, returns the value stored there.