Function pointer definition:
Void (* point_fun) (const char * str );
Point_fun is first combined with * as a pointer and () as a function operator, so this pointer points to the Function
[Cpp]
# Include <stdio. h>
Void say_hello (const char * str );
Void (* point_say_hello) (const char * str); // point_say_hello is first combined with * as a pointer and () as a function operator, so this pointer points to the Function
Typedef void FUN (const char * str); // defines a FUN function type.
FUN say_typedef; // use the type definition defined above. FUN variables are equivalent to declaring a function.
FUN * point_say_typedef; // use the type definition defined above. The FUN type pointer is equivalent to defining a function pointer.
Void (* say_table [2]) (const char * str); // according to the sequence of operators, say_table is an array. The elements of an array are pointers to functions.
// Void (* say_table [2]) (const char * str) = {point_say_hello, point_say_typedef };
# Define say_interface (a) say_table [a] ("lang") // equivalent to the interface
Typedef void (* POINT_FUN) (const char * str); // defines the function pointer type of a POINT_FUN class.
POINT_FUN point_fun;
Void main (){
Printf ("lang start \ n ");
Point_say_hello = say_hello;
Point_say_hello ("langxw ");
Point_say_typedef = say_typedef;
Point_say_typedef ("langxw ");
Say_table [0] = point_say_hello;
Say_table [1] = point_say_typedef;
Say_interface (0 );
Say_interface (1 );
Point_fun = say_hello;
Point_fun ("point_fun ");
}
Void say_hello (const char * str ){
Printf ("hello % s \ n", str );
}
Void say_typedef (const char * str ){
Printf ("typedef % s \ n", str );
}
# Include <stdio. h>
Void say_hello (const char * str );
Void (* point_say_hello) (const char * str); // point_say_hello is first combined with * as a pointer and () as a function operator, so this pointer points to the Function
Typedef void FUN (const char * str); // defines a FUN function type.
FUN say_typedef; // use the type definition defined above. FUN variables are equivalent to declaring a function.
FUN * point_say_typedef; // use the type definition defined above. The FUN type pointer is equivalent to defining a function pointer.
Void (* say_table [2]) (const char * str); // according to the sequence of operators, say_table is an array. The elements of an array are pointers to functions.
// Void (* say_table [2]) (const char * str) = {point_say_hello, point_say_typedef };
# Define say_interface (a) say_table [a] ("lang") // equivalent to the interface
Typedef void (* POINT_FUN) (const char * str); // defines the function pointer type of a POINT_FUN class.
POINT_FUN point_fun;
Void main (){
Printf ("lang start \ n ");
Point_say_hello = say_hello;
Point_say_hello ("langxw ");
Point_say_typedef = say_typedef;
Point_say_typedef ("langxw ");
Say_table [0] = point_say_hello;
Say_table [1] = point_say_typedef;
Say_interface (0 );
Say_interface (1 );
Point_fun = say_hello;
Point_fun ("point_fun ");
}
Void say_hello (const char * str ){
Printf ("hello % s \ n", str );
}
Void say_typedef (const char * str ){
Printf ("typedef % s \ n", str );
}
End