I. pointer array
1. The array of function parameters of the table pointer is actually
sizeof(a) == sizeof(int * );
int a[ ] ⇔ int *a
The following four function prototype is equivalent to:
- you sum (you ar *, you're n);
- you sum (you ar [], you're n);
- int sum (int *, int);
- int sum (int[ ],int);
2. The array variable is a special pointer
- Array itself indicates the address,
- int a[10];
- int * p = a; // no need to take a variable &
- Expression of cell array is a variable, & need to take address.
- [] Operator can make the array, a pointer can be done;
P [0] ⇔ A [0] * Operator can use the pointer, the array can be made;
Const array variable is a pointer type, and therefore can not be changed assignment;
int A [] ⇔ const int * B;
II. Pointer arithmetic
(1) to add a pointer, a subtraction integer (+, + =, -, - =);
(2) increment decrement (+, -);
(3) subtracting two pointers;
1. Modified:
- I.e., plus a pointer to the address indicated by the pointer value plus a sizeof (pointer type), move to the next cell.
- Pointer 1 - direction of the cell 2 is the difference between the result of, not the value of the address difference between:
(Pointer 1-- Pointer 2) / sizeof (pointer type);
2. *p++
- After removing the data referred to p, p is moved to the next cell;
- An array of space-based continuous operation;
- In some CPU, which can be directly translated into an assembler instruction;
3. Compare pointer
- ! <, <=, ==,>,> =, = pointer may be compared (compare memory address);
- Address of the array increases linearly.
4.0 Address
- A 0 address is typically not able to touch the random address;
- Pointer should not have a value of 0;
- Usually expressed special things with 0 Address:
- Return an invalid value;
- Pointer is not actually initialized.
- NULL is a predefined symbols, represents the address 0
The pointer type
- No matter what type of points, the size of all the pointers are the same, because all addresses;
- Pointers point to different types of assignment is not directly to each other; this is to avoid using the wrong hands.
6. The pointer action
- When passed as an argument requires large transactions;
- After passing an array of arrays to do the operation;
- Function returns more than one result;
- Need to modify more than one variable function;
- Dynamic application memory.
My handwritten notes
MOOC Code
Issues arising
1. * p ++ meaning
Resolution: The unary * + and below the level of the value P taken out after the P position to the next.