Thanks for the response.
The thing is that its an exercise from the book and english is not my first language so maybe i understood it wrong:
Create a program that defines two Int arrays, one right after the other. Index off the end of the first array into the second, and make an assignment. Print out the second array to see changes cause by this. Now try defining a char variable between the first array definition and the second, and repeat the experiment.
This is obviously terrible to do in practice, but okay as an exercise. The issue is that array1 and array2 aren't laid out in memory in that order, but in the reverse order. I'm assuming you are on a 64bit architecture? Try *(array2+2) = 10;, and check the value of array1.
The two arrays are not necessary placed right after each other in memory. The compiler can place them wherever it wants. From your output you can see that array2 is placed 16 bytes earlier in memory than array1. Note that the array elements only take up 8 bytes (assuming sizeof(int) == 4) so there is some space in between.
Placing the arrays inside a class you get better guarantees about the order of the arrays but there can still be some space in between them.