to illustrate the address location
Code:
#include <iostream>
using namespace std;
void printFirst(int* first)
{
cout << *first << endl;
}
int main()
{
int arr[4] = {1, 2, 3, 4};
printFirst(arr);
return 0;
}
printFirst takes a pointer to int. In main I create an array with 4 elements. Then when I call printFirst I pass it the variable name, which is actually the address of the first element in the array. I would get the same effect as calling printFirst(&arr[0]);
if I wanted to iterate through the array I owuld just increment the pointer in the printFirst Method as so
Code:
void printFirst(int* first)
{
for(int i = 0; i < 4; ++i)
{
cout << *first << " ";
++first;
}
cout << endl;
}