The pointer in c is very important, but after studying c for so long, I don't know how to use the pointer array pointing to the function. In fact, it is similar to using the function pointer.
We can create an interesting structure to point to the pointer array of the function. To select a function, you only need to use the subscript of the array and then indirectly reference this pointer. This method supports the table-driven code concept. You can select the function to be executed based on the state variable (or the combination value of the state variable, instead of conditional statements or case statements. This design method is useful for adding or deleting functions from a table (or dynamically creating or changing a table.
# Include <stdio. h> void fun1 (); void fun2 (); void fun3 (); void main () {void (* fun [3]) () = {fun1, fun2, fun3}; // The Declaration of the pointer array pointing to the function int a; printf ("enter a 1, 2, or 3. enter 0 to exit. \ N "); scanf (" % d ", & a); while (a) {if (a = 1 | a = 2 | a = 3) {fun [A-1] (); // call the function printf in the array through the function pointer ("enter a 1, 2, 3. enter 0 to exit. \ n "); scanf (" % d ", & a) ;}else {printf (" enter a valid number (1-3 ). 0. Exit. \ N ") ;}} void fun1 () {printf (" function f1 is called !. \ N ");} void fun2 () {printf (" function f2 is called !. \ N ");} void fun3 () {printf (" function f3 is called !. \ N ");}