// Author: Keith Shomper // Date: 10/10/03 // Purpose: To demonstrate array declaration and initialization #include using namespace std; // declare an array object in the 'global' namespace int a[5]; int main() { const int SIZE = 5; string s; // declare other array objects, of various initializations int b[SIZE]; int c[SIZE] = {1}; int d[SIZE] = {1, 2, 3, 4, 5}; char alpha1[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char alpha2[] = "abcdefghijklmnopqrstuvwxyz"; // Print out the contents of array 'a' cout << "The array 'a' has the values: "; for (int i = 0; i < SIZE; ++i) { cout << a[i] << " "; } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Print out the contents of array 'b' cout << endl << "The array 'b' has the values: "; for (int i = 0; i < SIZE; ++i) { cout << b[i] << " "; } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Print out the contents of array 'c' cout << endl << "The array 'c' has the values: "; for (int i = 0; i < SIZE; ++i) { cout << c[i] << " "; } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Print out the contents of array 'd' cout << endl << "The array 'd' has the values: "; for (int i = 0; i < SIZE; ++i) { cout << d[i] << " "; } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Print out the contents of array 'alpha1' cout << endl << "The array 'alpha1' has the values: "; for (int i = 0; i < 26; ++i) { cout << alpha1[i]; cout << ((i == 12) ? "\n" : " "); } cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); // Print out the contents of array 'alpha2' cout << endl << "The array 'alpha2' has the values: "; for (int i = 0; i < 26; ++i) { cout << alpha2[i]; cout << ((i == 12) ? "\n" : " "); } cout << "'" << ((alpha2[26] == '\0') ? 'n' : alpha2[26]) << "'"; cout << endl << endl << "Press enter to continue .... "; getline(cin, s, '\n'); return 0; }