//------------------------------------------------------------------------ // Simple array examples // //------------------------------------------------------------------------ #include using namespace std; struct Time { int hours; int minutes; int seconds; }; void myFunction(int changeArray[]) { int i; cout << endl << " In the function call: "; for (i=0; i<10; ++i) { changeArray[i]=changeArray[i]*2; cout << " " << changeArray[i]; } } int main () { int i; // just used for counting int myArray [5] = {0,0}; // had to see if this reall worked and it does! cout << "Wow, the value of index 4 is " << myArray[4] << " !"<< endl << endl; int AnotherArray[]={0,1,2,3,4,5,6,7,8,9}; // lets create another array // here are the values before the function call cout << endl << "Before the function call: "; for (i=0; i<10; ++i) { cout << " " << AnotherArray[i]; } myFunction(AnotherArray); // now lets send it to a function // after the function call, what are the values? cout << endl << " After the function call: "; for (i=0; i<10; ++i) { cout << " " << AnotherArray[i]; } cout << endl; Time myTimes[5]; // lets just set all the times to 12:00:00 - we lost the power for (i=0; i<5; ++i) { myTimes[i].hours = 12; myTimes[i].minutes = 0; myTimes[i].seconds = 0; } // lets see what times we have cout << endl << "Boring times stored in a struct:" << endl << endl; for (i=0; i<5; ++i) { cout << myTimes[i].hours << ":" << myTimes[i].minutes << ":" << myTimes[i].seconds << endl; } getchar(); return 0; }