This article is to learn the "C + + Programming Tutorial-design ideas and implementation" notes.
Pointers can be added and reduced.
The array name itself, with no square brackets and subscript, is actually an address that represents the array start address.
The array name of an integer array gets an integer address, and the array name of the character array gets the one-character address.
The array start address can be assigned to a pointer and manipulated by moving the pointer (plus minus the pointer) to the group element.
For example: The following program uses pointer arithmetic to calculate the and of the array elements:
#include <iostream.h>
int main () {
int iarray[10];
int sum = 0;
int * Iptr = iarray;//is initialized with the array name IArray to the pointer
int *iptr;
Iptr = IArray; The two sentences are equal to the above sentence//iptr = &iArray[0]; This sentence is the same as the one on the left
for (int i = 0;i < 10;i++) {
Iarray[i] = i * 2;
cout<< "*iarray[" <<i<< "]" << "is" <<iArray[i]<<endl;
}
for (int idex = 0; Idex < idex++) {
sum + = *iptr;
cout<< "*iptr is" <<*iPtr<<endl;
iptr++;
}
cout<< "Sum is" <<sum<<endl;
}
Because the pointer is an address that has a data type, the pointer operation is expanded in the data type.
Pointer Operations (c + +)