// File: new1.C // // Where do dynamically data live? #include // Global variable int x ; void func1() { int a ; cout << "In func1(), &a = " << &a << "\n" ; } main() { int i ; int *A, *B, *C ; cout << "In main(), &i = " << &i << "\n" ; cout << "Global variable x, &x = " << &x << "\n" ; func1() ; A = new int[10] ; // dynamically allocated array of int cout << "In main, A = " << A << "\n" ; B = new int[5] ; cout << "In main, B = " << B << "\n" ; // Initialize B for (i = 0 ; i < 5 ; i++) { B[i] = 200 + i ; } cout << "\nCheck contents of B\n" ; for (i = 0 ; i < 5 ; i++) { cout << " B[" << i << "] = " << B[i] << "\n" ; } // Overrun array A! for (i = 0 ; i < 20 ; i++) { A[i] = 100 + i ; } cout << "\nCheck contents of B (again)\n" ; for (i = 0 ; i < 5 ; i++) { cout << " B[" << i << "] = " << B[i] << "\n" ; } cout << "\nOops! ...\n" ; cout.flush() ; delete [] A ; delete [] B ; C = new int[50] ; }