1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
//Thenewboston.com C++ Video Lesson 35 - Passing Arrays To Functions
#include <iostream>
using namespace std;
void printArray(int theArray[], int arraySize);
int main()
{
int array1[5] = {5,4,3,2,1};
int array2[6] = {6,5,4,3,2,1};
printArray(array2, 6);
//tell it the identifier of the array ONLY, and the size you pass as an argument.
//this replaces the variables theArray and arraySize in the printArray function.
return 0;
}
void printArray(int theArray[], int arraySize)
//the variables theArray hold the array, arraySize holds size of array
{
for(int x = 0;x<arraySize;x++)
//use a for loop to count the array element starting at 0 always.
{
cout << theArray[x] << endl;
//each time this loop runs through, it will up the value of x and print out the
//corresponding element of the array.
}
}
|