When you initialize an array, each initializer sets an element of the array regardless of how many bytes each element takes up.
You machine is probably using little-endian byte ordering. That means that array
looks like this in memory:
-----------------------------------------------------------------
| 1 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 3 | 0 | 0 | 0 | 4 | 0 | 0 | 0 | ...
-----------------------------------------------------------------
| [0] | [1] | [2] | [3] | ...
Each value of type uint32_t
is 4 bytes long with the least significant byte first.
When you do (char*)array
that casts array
(converted to a pointer) to a char *
, so any pointer arithmetic on a char *
increases the address by the size of a char
, which is 1.
So (char*)array + 8
points here:
(char*)array + 8 ------------------
v
-----------------------------------------------------------------
| 1 | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 3 | 0 | 0 | 0 | 4 | 0 | 0 | 0 | ...
-----------------------------------------------------------------
| [0] | [1] | [2] | [3] | ...
That pointer is then converted to a uint32_t *
and dereferenced, so it reads the value 3.