One:
function and pointer relationships:
1) Pointer to function
2) pointers as arguments to functions
int max (int *p1,int *p2) {
}
1) An argument can be a pointer
2) can also be an array name of an array of the same type as the formal parameter
3) The return value is a function of the pointer:
Pointer functions
char* function name () {
return address
}
The return value is a string pointer
char * Test () {
return "XXXX";
}
char * TEST2 () {
Char ch= ' a ';
Return &ch;
}
Two: pointers to functions:
1) Pointer to function
function in memory will be divided into a separate area of memory, function name represents the memory of the functions of the first address
Represents the first memory address: Array name variable name Function name structure body name
2) Function Pointers:
Pointer variable to hold the address of the function
Format:
int max (int x,int y) {
Return x>y?x:y;
}
int sum (int x,int y) {
return x+y;
}
int * Getmax (int x,int y) {
Return x>y?&x:&y;
}
The format of the Declaration
int max (int x,int y);
To eject a function pointer by declaring
return value type (* pointer variable name) (parameter of function);
Defines a function pointer variable p,p can point to all return values that are int,
Functions with two shaping parameters
Int (*p) (int x,int y);
Note: When defining a function pointer, you can not specify the shape parametric name, but the type cannot be omitted
Int (*P1) (int,int);
3) Use of function pointers
(1) class to function pointer
Int (*p) (int x,int y);
Initialize the function pointer with the name of the function
p = sum;
(2) Calling functions with pointer variables
P (4,5);
Pros: Make function calls more flexible
The pointer to the block in OC is very similar to the function pointer
The relationship between the C language pointer and the function