Code:
char i;
int* p = (int*) &i;
...
*p = 1234567892;
...
No compiler will complain; everything seems fine. Yet clearly we are storing a binary code for the integer value 1234567892 that takes 32 bits (01001001100101100000001011010100) at the address of the variable i that has the size of 8 bits
There are several possible outcomes.
If the whole part X of the memory in Figure 3.1 belongs to the running program (process), then:
if X does not contain any data important for the rest of the execution of the program, then the program runs fine and there is no apparent problem;
if X does contain important data that are overridden by the 100101100000001011010100 tail of the binary code but by pure chance this does not change anything (as the data stored therein just happened to be the same), then the program runs fine and there is no apparent problem;
if X does contain important data that are overridden and thus changed, then
incorrect results may be produced or
the program may crash with all kinds of possible error messages.
If all or part of X belongs to some other process, then the program is terminated by the operating system for a memory access violation (the infamous UNIX segmentation fault error).