In C, a pointer can point to a function. This pointer also has two attributes, but one is the function entry address and the other is the function return value type. For example, the following program is correct in C:
Int time12 (int I)
{Return (I % 12 );
}
Int main ()
{Int (* fp) () = time12;
Intt = fp (13 );
Return0;
}
The first sentence of the main function is a Definition Statement. We should start from the identifier on the left of the equal sign. All types of symbols except the identifier on the left of the equal sign must be read in the read order according to the operation level when the symbol is used as the operator. Fp is a pointer pointing to a function (Note: C language allows its parameter type not to be written) the return value of this function is int, And the pointer is initialized as the entry address of the function time12.
However, the first statement of the above program in C ++ is regarded as wrong. C ++ is a strongly typed check language, which is related to the function overload mechanism of C ++. C ++ requires that all types of formal parameters of the function be specified. The following program is the correct C ++ program:
Int time12 (int I)
{Return (I % 12 );
}
Int main ()
{Int (* fp) (int) = time12;
Intt = fp (13 );
Return0;
}