What is the difference between pointer functions and function pointers

xiaoxiao2021-03-05  37

What is the difference between the pointer function and the function pointer 1. These two concepts are referred to as the pointer function refers to a function of the pointer, that is, the essence is a function. We know that the function returns a type (if not returned, it is valid), but the pointer function return type is a certain type of pointer. Its definition format is shown below: Return Type Identifier * Returns Name (Form Parameter Table) {Functional Body} Return Type can be any basic type and composite type. The use of functions returned to the pointer is very wide. In fact, every function, even if it does not bring a type of pointer, it has an entry address, which is equivalent to a pointer. For example, the function returns a whole value, which is actually equivalent to the value of a pointer variable, but the variable at this time is the function itself, and the entire function is equivalent to a "variable". For example, the following returns an example of the pointer function: #include float * find (); main () {static float score [] [4] = {{60, 70, 80, 90}, {56, 89, 34, 45} {34, 23, 56, 45}}; float * p; INT I, M; Printf ("Enter the number to be bound:"); Scanf ("% D", & M); Printf ("The score of NO.% D are: / n ", m); p = find (score, m); for (i = 0; i <4; i ) Printf ("% 5.2f / t ", * (p i) );} float * find (FLOAT (* Pionter) [4], INT N) / * Defines the pointer function * / {float * pt; pt = * (Pionter n); return (PT);} Student number On the 0 number, the function Find () is defined as a pointer function, and the envelope Pointer is a pointer variable that points the needle to the one-dimensional array of four elements. Pointer 1 points to the first line of Score. * (Pointer 1) points to the 0th element of the first line. PT is a pointer variable that points to floating point variables. The file () function is called in the main () function, pass the first address of the score array to Pointer. 2, "Function Pointer" is a pointer variable to the function, so "function pointer" itself should first be a pointer variable, but this pointer Variable points function. This is just like the pointer variables can point to integer variables, characters, arrays, here is a pointing function. As mentioned earlier, C is compiled, each function has an inlet address, the entrance address is the address pointed to by the function pointer. With the pointer variables of the function, you can use the pointer variable call function, just like the same type variable with the pointer variable, which is consistent. The function pointer has two purposes: call the function and the parameters of the function. The description method of the function pointer is: Data type flag (* pointer variable name) (parameter); Note: The parameters in the braces can be available, depending on the situation.

转载请注明原文地址:https://www.9cbs.com/read-34022.html

New Post(0)