------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
One, the pointer variable definition 1. The format of the definition
L Class name identifier * pointer variable name ;
l int *p;
2. Define the Post assignment first
L Simple Value
int a = 10;
int *p;
p = &a;
printf ("%d", *p);
L Simple Change value
*p = 9;
3. Assigning values at the same time as defined
int a = 10;
int *p = &a;
4. Implement modify argument 5. Watch out.
l int *p; p = 1000;
l int *p; *p = 100;
l int *p; *p = &a;
L%p The address value stored in the output pointer
L Other pointer type description, such as float *p; char *p;
L can not use the type, such as int a = 10; float *p = &a;
6. Clear the pointer
L p = 0;
L p = NULL;
Second, pointers and Arrays 1. Pointer to a one-dimensional array element 2. Traversing one-dimensional array elements with pointers
L Iterate through the char array (' i ', ' t '), and then iterate through the array of int types
the difference between L * (p+i) and * (p++)
L a+i and a++
L p[0],p[1]
Third, pointer and string 1. String review
Char s[] = "Jake";
2. Other ways to define strings
Char *s = "Jake";
Or
Char *s;
s = "Jake";
3. The difference between the two ways of definition
L Memory Analysis
L Drawing Analysis
L The difference between a constant and a variable string
L Constant Memory address view
Iv. functions that return pointers
The pointer is also a data type in C, so the return value of a function can certainly be a pointer-type
L The general form of a function that returns a pointer is: type name * Function name ( parameter list )
V. Pointer to function 1. Why can pointers point to a function?
function as a program, in memory also occupy a portion of storage space, it also has a starting address, that is, the entry address of the function. function has its own address, that's good, our pointer variable is used to store the address. Therefore, a pointer can be used to point to a function. Where the function name represents the address of the function.
2. Definition of pointers to functions
General form of definition: The return value type of the function (* pointer variable name ) ( parameter 1, parameter 2, ...);
3. Use note
L because this type of pointer variable stores the entry address of a function, it makes no sense to add or subtract them (such as p++)
The pointer variable that points to a function has two main uses:
· Calling functions
· Passing functions as arguments between functions
Dark Horse programmer--c Language Foundation---pointers