#include <iostream> using namespace std; int main () { const int MAXST = 5 ; // Strongly recommended : capital + array size int i ; // Declaring and initializing an array : data type , name , size // Initialization is optional double store[MAXST] = { 1.2 , 4.5e+1 , 7.9 , -0.2 , 1100. } ; int help[3] = { 4 , 2 } ; // Partial initialization int hope[3] ; // No initialization char name[6] ; // No initialization, 5 char long C-string char month[] = "June" ; // month[] will be 4+1 bytes long !!! int someday = 17 ; cout << month[0] << endl ; cout << month << endl ; for ( i=0;i<=MAXST;i++ ) // Index of array starts with 0 (zero) { // Error : Should be i < MAXST, but error // demonstrates how careful the programmer // has to be. cout << "store[" << i << "]= " << store[i] << endl ; } for ( i=0;i<3;i++ ) { // Observe that help[2] has not been given a value as of yet. // Hence, you never know what value it has. cout << "help[" << i << "]= " << help[i] << endl ; } // Different ways to access array elements. Basically, whenever // you were using a simple variable in the past you could use // an array element. The index of an array element can be // either an integer value, an integer variable or a mathematical // expression resulting in an integer value. help[2] = someday ; // help[2] carries now the value of someday = 17 someday = help[0] ; // now someday has the value of help[0]=4 i = 0 ; help[i+1] = ( help[2] + help[0] ) / 2 ; // help[1] = ..... }