// Copyleft: Sathiamoorthy Manoharan. #include int main() { const int MYMAX = 4; int array1[MYMAX]; int array2[MYMAX]; for ( int i = 0; i < MYMAX; ++i ) { array1[i] = 2*i; array2[i] = 3*i; } std::cout << "array1:\n"; for ( int i = 0; i < MYMAX; ++i ) { std::cout << i << "\t" << array1[i] << "\t" << (unsigned long) (&array1[i]) << "\n"; } std::cout << "array2:\n"; for ( int i = 0; i < MYMAX; ++i ) { std::cout << i << "\t" << array2[i] << "\t" << (unsigned long) (&array2[i]) << "\n"; } // We are modifying array2 here, but note that we are going well over // the size of the array. Notice what we see in the output of this // program and understand what's going on under the hood. std::cout << "modifiying array2:\n"; for ( int i = 0; i < 2*MYMAX; ++i ) { array2[i] = 4*i; } std::cout << "array1:\n"; for ( int i = 0; i < MYMAX; ++i ) { std::cout << i << "\t" << array1[i] << "\t" << (unsigned long) (&array1[i]) << "\n"; } std::cout << "array2:\n"; for ( int i = 0; i < MYMAX; ++i ) { std::cout << i << "\t" << array2[i] << "\t" << (unsigned long) (&array2[i]) << "\n"; } return 0; }