It is a pointer to Function. Let me show you if you try to make an application in C that will use text menus where instead of switch I will use pointer to Function:
#include <stdio.h>
#include<unistd.h>
void clearScreen( const int x );
int exitMenu( void );
int mainMenu( void );
int updateSystem( void );
int installVlcFromPpa( void );
int installVlcFromSource( void );
int uninstallVLC( void );
int chooseOption( const int min, const int max );
void showMenu( const char *question, const char **options, int (**actions)( void ), const int length );
int installVLC( void );
int meniuVLC( void );
void startMenu( void );
int main( void ){
startMenu();
return 0;
}
void clearScreen( const int x ){
int i = 0;
for( ; i < x ; i++ ){
printf( "\n" );
}
}
int exitMenu( void ) {
clearScreen( 100 );
printf( "Exiting... Goodbye\n" );
sleep( 1 );
return 0;
}
int mainMenu( void ){
clearScreen( 100 );
printf( "\t\t\tMain Manu\n" );
return 0;
}
int updateSystem( void ) {
clearScreen( 100 );
printf( "System update...\n" );
sleep( 1 );
return 1;
}
int installVlcFromPpa( void ) {
clearScreen( 100 );
printf("Install VLC from PPA \n");
sleep( 1 );
return 0;
}
int installVlcFromSource( void ) {
clearScreen( 100 );
printf( "Install VLC from Source \n" );
sleep( 1 );
return 0;
}
int uninstallVLC( void ) {
clearScreen( 100 );
printf( "Uninstall VLC... \n" );
sleep( 1 );
return 1;
}
int chooseOption( const int min, const int max ){
int option,check;
char c;
do{
printf( "Choose an Option:\t" );
if( scanf( "%d%c", &option, &c ) == 0 || c != '\n' ){
while( ( check = getchar() ) != 0 && check != '\n' );
printf( "\tThe option has to be between %d and %d\n\n", min, max );
}else if( option < min || option > max ){
printf( "\tThe option has to be between %d and %d\n\n", min, max );
}else{
break;
}
}while( 1 );
return option;
}
void showMenu( const char *question, const char **options, int ( **actions )( void ), const int length) {
int choose = 0;
int repeat = 1;
int i;
int ( *act )( void );
do {
printf( "\n\t %s \n", question );
for( i = 0 ; i < length ; i++ ) {
printf( "%d. %s\n", (i+1), options[i] );
}
choose = chooseOption( 1,length );
printf( " \n" );
act = actions[ choose - 1 ];
repeat = act();
if( choose == 3 ){
repeat = 0;
}
}while( repeat == 1 );
}
int installVLC( void ) {
clearScreen( 100 );
const char *question = "Installing VLC from:";
const char *options[10] = { "PPA", "Source", "Back to VLC menu" };
int ( *actions[] )( void ) = { installVlcFromPpa, installVlcFromSource, mainMenu };
size_t len = sizeof(actions) / sizeof (actions[0]);
showMenu( question, options, actions, (int)len );
return 1;
}
int meniuVLC( void ) {
clearScreen( 100 );
const char *question = "VLC Options";
const char *options[10] = { "Install VLC.", "Uninstall VLC.", "Back to Menu." };
int ( *actions[] )( void ) = { installVLC, uninstallVLC, mainMenu };
size_t len = sizeof(actions) / sizeof (actions[0]);
showMenu( question, options, actions, (int)len );
return 1;
}
void startMenu( void ){
clearScreen( 100 );
const char *question = "Choose a Menu:";
const char *options[10] = { "Update system.", "Install VLC", "Quit" };
int ( *actions[] )( void ) = { updateSystem, meniuVLC, exitMenu };
size_t len = sizeof(actions) / sizeof (actions[0]);
showMenu( question, options, actions, (int)len );
}
Compile it and try it.