1. The addition and subtraction of pointers is measured in data elements, not bytes
* (A + K) equivalent to A[k] &a[k] equivalent to a + K
2. The difference between a pointer and an array: the array has storage space and can store the data
Pointers can only be used to save addresses, no storage space
3. Dynamic array: Example: Scores = (int *) malloc (num * sizeof (int));
if (Scores = = NULL)
Goto Error;
Note: The malloc function returns a null pointer of type void, so the type conversion must be enforced
Need to add error handling
Use array subscript and pointer methods to access
Static arrays are stored in the stack frame, and dynamic arrays are stored in the heap
4. Use the free (...) after using the dynamic array; Release
5. Array of pointers: example: void main (int argc, char *argv[])
ARGC: Holds the number of arguments (including program name), and the element in argv is an array of characters of the base type
6. Pointers pointing to pointers
Example: void get (int **array) {
*array = (int *) malloc (count * sizeof (int));
...}
The address in the keynote function is passed to the called function, and the parameters and arguments are both pointers
The address in the called function is passed to the keynote function, and both the formal parameter and the argument are pointers to pointers (or function return values)
7. Two-d arrays and pointers
When a two-dimensional array is stored in the C language, it does not hold a two-dimensional table, but is stored sequentially, that is, one after another to store
A[I][J]: Corresponding address: A + k * sizeof (int), k = i * Number of elements per line + j
A[i]: One-dimensional array, example: a[0] + 1 point to a[0][1]
A: Point to a fixed-length, one-dimensional array, with each step spanning the length of the array, e.g. A + 1 pointing to a[1]
8. If you call A[i][j]:
Operation on one line: Test1 (A[i]); Test1 parameters: int *pa or int pa[] or int pa[4]
Array operations: Test2 (a); Test2 parameters: Int (*arr) [4] or int arr[][4] or int arr[3][4]
9. Dynamic two-dimensional array
Example: a = (int (*) [4]) malloc (nRows * nCols * sizeof (int));
C Language Learning notes-8. Pointers