Pointers and Arrays
intA[] = {1,2,3,4,5}; int*p; P=A; printf ("*a =%d\n",*a); printf ("*p =%d\n",*p); printf ("a[1] =%d\n", a[1]); printf ("p[1] =%d\n"-P:1]);
The array name is the first address of the array. The above output is the same. The array name is basically equivalent to the pointer. But a is a constant, can not do a++ or a+=1, and the pointer P can be.
pointer arrays and Arrays pointers
Data type * variable name []// First it is an array, the element of the array is a pointer, which means that each element stores the contents of an address int *a[5]; Data type (* variable name) []// First it is a pointer to an array int (*a) [5];
pointer functions and function pointers
Type identifier * function name (parameter table)// pointer function, which is a function, the return value is a pointer int *f (x, y); type identifier (* function name) ( Parameter table)// function pointer int (*f) (int x); // The function address is assigned to the function pointer f = &= function // Use function pointer to call functions x = (*f) (); // = f ( );
Pointer calculation
Self-increment: increase or decrease by the length of the data type it refers to
int Ten ; int *p; = &A; printf ("%p\n", p); P+ +; printf ("%p\n", p);
Operation Result:
0X7FFF5FBFF7FC 0x7fff5fbff800
You can see two results with a difference of 4, which is the byte length of int.
C Study notes-pointers