C++: Pointers and Arrays
Arrays and pointers have a close relationship. As we will soon see, an array in C++, is basically a constant pointer.
Before going on, copy and paste the code below to see the relationship between pointers and arrays.
#include ≤iostream>
#include ≤fstream>
using namespace std;
int main()
{
const int SIZE = 5;
int numbers[SIZE];
int count;
cout<<"enter " << SIZE <<" numbers, press 'enter' after each number "<< endl;
for(int count=0;count <SIZE; count++){
cin>> *(numbers +count);
}
cout << "Here are the numbers (subscript syntax)" << endl;
for(count =0; count < SIZE; count++)
cout<< numbers[count] <<endl;
cout<<"\n Using pointer notation "<< endl;
for(count =0; count < SIZE; count++)
cout<< *(numbers + count) << endl;
return 0;
}