The contents of arrays and multidimensional arrays are no longer discussed here, as explained in the previous tutorial, where the relationship between the array and the pointer type is more deeply understood by the understanding of the relationship between the array and the pointer.
An array of integer types is defined as follows:
int a[]={1,2,3,4};
If you simply write:
Identifier name of the a;//array
This will represent the memory address of the first element of the array, A; it is equivalent to &a[0], its type is a pointer to an array element type, in this case its type is int*
If we want to access the address of the second element we can write the following two ways:
&a[1];
a+1//Note that the representation here is to move the starting address of a array to the last one, to the address of the second element, i.e. a[0] to a[1]!
The relationship between the array name and the pointer is actually very simple, in fact, the array name represents the array of the first element of the memory address, which is similar to the principle of the pointer!
Here we look at a complete example, using pointers to achieve circular traversal of the array elements of access!
#include <iostream>
using namespace Std;
void Main (void)
{
int a[2]={1,2};
int *pb=a; Defines the address of the pointer *PB the starting address for array a
int *pe=a+2; Defines the address of the pointer *PB the end address of array a
cout << a << "|" << a[0] << "|" << * (a+1) << "|" << PB << "|" << *PB <<endl;
while (PB!=PE)//using the address to logically determine whether the end address of the array is reached
{
cout << *PB << Endl;
pb++; Increments the PB's memory address backwards in the loop using the increment operation
}
Cin.get ();
}