// arr3.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This program mainly illustrates how arrays can be initialized. // Key Points: 1) Arrays with no indicated size. // 2) Copying one array to another. Notice how the copying // operation should be done. #include void ArrayInt() { const arrsize = 6; double arr1[arrsize] = {12.3, 2.8, 5.34, 9.43, 12.15, 32.9}; cout << "\n Here is arr1 after initialization: " << endl; for (int i = 0; i < arrsize; i++) cout << arr1[i] << "\t"; double arr2[arrsize]; // Array of 6 elements of double values // Copy arr1 to arr2 for ( i = 0; i < arrsize; i++) arr2[i] = arr1[i]; cout << "\n Here is arr2 after being copied from arr1: " << endl; for ( i = 0; i < arrsize; i++) cout << arr2[i] << "\t"; int arr3[] = {12, 13, 4, 9}; // This creates and initializes an array // of 4 elements. cout << "\n Here is arr3 after being created: " << endl; for ( i = 0; i < 4; i++) cout << arr3[i] << "\t"; int arr4[7] = {23, 7, 9, 21}; // Create an array of 7 elements, and // initialize only the first 4 elements // Notice that the last three elements // include just garbage. cout << "\n Here is arr4 after being created: " << endl; for ( i = 0; i < 7; i++) cout << arr4[i] << "\t"; } int main() { ArrayInt(); return 0; } // If compiling the program in HP-UX, compile with +a1, since array initialization // The output of the program /* Here is arr1 after initialization: 12.3 2.8 5.34 9.43 12.15 32.9 Here is arr2 after being copied from arr1: 12.3 2.8 5.34 9.43 12.15 32.9 Here is arr3 after being created: 12 13 4 9 Here is arr4 after being created: 23 7 9 21 0 0 0 */