1. Pointer to an arraywithPointer to an arrayHere,Pointer to an arrayIt points to an arrayPointer to the, its essence isPointer to the, pointing to the objectAn array of. Array Pointers can be expressed in a variety of forms. In the same way,Pointer to an arrayThat’s where the Pointers areAn array of, its essence isAn array of. Due to the[]Is of higher priority than*The priority of,Pointer to an arraywithPointer to an arrayCan be done as follows:
int * p1 [10]; Int (* p2)[10]; int (* p2)[10]; int (* p2)[10]; [10] specifies the number of elements in the array. [10] specifies the number of elements in the arrayCopy the code
  • Because the pointer to the array and pointer to general integer variables is different, can again to the array name here and the relationship between & array name and understanding In one dimensional array, the array name said pointing to the first address of the first, is a pointer to the common variables constant, when the + 1 offset is a common data type of memory size. The array name is preceded by an ampersand, which represents a pointer constant to the array. The offset is the memory size of the array

  • int p; // This is a normal integer variable

  • int *p; Int * P * P * P * P * P * P * P * P * P * P

  • int p[3]; // P is an array of integer data. // P is an array of integer data

  • int *p[3]; / / first start from P, combined with [], because of its high priority than *, so P is an array, and then combine with *, explain the elements in the array is a pointer type, and then combine with int, explain the contents of the pointer points to is of type integer, so P is a composed of returns the integer data pointer array

  • int (*p)[3]; // We combine P with * to indicate that P is a pointer, then with [] to indicate that the pointer points to an array, then with int to indicate that the elements of the array are integers, so P is a pointer to an array of integers

  1. You can further understand the above explanation by referring to the following topics
int arrayName[4] = {10, 20, 30, 40};
int *p = (int *)(&arrayName + 1);
NSLog(@"%d", *(p - 1));
Copy the code
  • The answer to parse
  1. (&arrayName + 1):&arrayNameIs the address of the array (equivalent to pointing toArrayName Pointer to an array)
  2. increase1It will move backwards16 bytes, the beginning isFour bytes of spaceAfter movingThe position after 16 bytes(The current position is20 bytes)
  3. And then I assign it toThe int typeA pointer to thep(The int type takes 4 bytes)
  4. so(p - 1)isMinus 4 bytes, into16 bytesAnd the output of*(p - 1)A value of40

Attached: my blog address