The relationship between pointers and arrays based on the C language pointer, And the C language pointer Array
About arrays and pointers:
The base address of the array is the starting position for storing the array in the memory. It is the address of the first element in the array (subscript: 0). Therefore, the array name is an address, that is, the pointer value.
Int a [10], * p is equivalent to p = a and p = & a [0]
P = a + 1 and p = & a [1] are equivalent
* (A + I) is equivalent to a [I]
* (P + I) is equivalent to p [I]
Array length: sizeof (a)/sizeof (int)
Pointer variables are involved in displacement operations such as p + 1 and p + 2. moving a few bytes after each plus 1 is dependent on the pointer variable type (equivalent to the array badge + 1)
Int * p + 1 Move 4 bytes
Char * p + 1 Move 1 byte
For example:
Void sum (int * p, int n) {int sum = 0; for (int I = 0; I <n; I ++) {sum = sum + * (p + I); // or sum = sum + p [I];} printf ("sum = % d", sum );} void sum1 (int a [], int n) {int sum = 0; for (int I = 0; I <n; I ++) {sum = sum + a [I]; // or sum = sum + p [I];} printf ("sum = % d", sum);} int main () {int B [10] = {1, 2, 3, 4, 6, 7, 9, 5, 2, 11}; sum1 (B, sizeof (B)/sizeof (int); return 0 ;}