Let's say that you defined this:
As you can see visually, act follows CP_count.Code:int CP_count[5] = 0 ; int act = 0 ;
If the compiler happens to place act immediately following CP_count in the stack, and if you coded
then because 5 is out of range for the array, then the variable act would receive the value. This is what would get saved:Code:CP_count[0] = 0 ; CP_count[1] = 1 ; CP_count[2] = 2 ; CP_count[3] = 3 ; CP_count[4] = 4 ; CP_count[5] = 5 ;
The same situation could also occur if both CP_count and int were malloced, as they could be adjacent in storage.Code:CP_count[0] would be 0 CP_count[1] would be 1 CP_count[2] would be 2 CP_count[3] would be 3 CP_count[4] would be 4 act would be 5
This is a very simple example, and overlays can be much more complex than this.