First look at the function pointer int func2 (int x);/* declare a function */int (* q2) (int x);/* declare a function pointer */q2 = func2; /* assign the first address of the func function to the pointer f */int c = (* q2) (3 ); // 3 the usage of the function pointer can be basically illustrated for any real parameter in the above four sentences: The function pointer is a pointer to the function, to be exact, is a pointer to a specific type of function (the function and the function pointer type must match). The function pointer is used to save the first address of the function, that is, the function can be accessed through this pointer. Function pointerEquivalent to alias. Function pointers can point to a type of function, rather than a function, that isYou can assign a value again.. (See example 2) it is not difficult to use a function pointer. Just remember the black text above. Attach two simple examples: max (x, y) {(x> y? (* Ptr) (, =, & a, & = (*View Code
Example 2:
(* =View Code
Look at the pointer function again: int * func (int x);/* declare a pointer function */int * q;/* declare a pointer */q = func (3 ); // 3 the pointer function can be described in the preceding three statements for any real parameter:
A pointer function is a function that returns a pointer.So we can use a pointer of the same type to receive it when calling it in main.
Pointer functions can be used to solve many problems, such as the problem of returning multiple values.. (See the article "function return methods with multiple values)
Pointer functions are more frequently used, You must learn to use pointer function logic is simple, the structure is fresh, powerful, good quality, high efficiency, comparable to the best Fengjie, better... (For downlink), it is really a loss if you do not learn it. Example 3 is also from Baidu. I personally think it is classic. It involves pointer, array pointer, pointer function, and two-dimensional array assignment. The function returns multiple values, the difference between auto-increment of array pointer and auto-increment of pointer... Numerous knowledge. You can understand this basic pointer. Example 3:
#include <iostream>
* find ((* p) [], m);
score [] [] = {{,,,}, {,,,}, {,,,}};
* pf = NULL;
>> = find (score, m);
(i =; i <; i ++ << * (pf + i) << << * find ((* p) [], * pf == * (p + m);
Pf = * (p + m); // p is a pointer to a two-dimensional array, with * pointer to a one-dimensional array
This sentence is classic.