Suppose I have this array:
i = *( (uint32_t *)&arr );
It's illegal, because it breaks strict aliasing rules, resulting in undefined behaviour.
memcpy(&i, &arr, sizeof(i));
But do notice that this code assumes host endianness. If you need endianness independent code, use bit shifting and masking to combine 4 values in to integer, or swap bytes after
memcpy (compilers usually offer some kind intrisics for this).