Invoking function call using function pointer C program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TP)
Other info: none
To do: Invoking function call using function pointer C program example
To show: How to invoke the function call using function pointer in C programming
/* Invoking function using function pointer */
#include <stdio.h>
/* function prototype */
int somedisplay();
int main(void)
{
int (*func_ptr)();
/* assigning a function to function pointer as normal variable assignment */
func_ptr = somedisplay;
/* checking the address of function */
printf("\nAddress of function somedisplay() is %p", func_ptr);
/* invokes the function somedisplay() */
(*func_ptr)() ;
return 0;
}
int somedisplay()
{
printf("\nI'm in somedisplay()...\n");
return 0;
}
Output example:
Address of function somedisplay() is 004111C7
I'm in somedisplay()...
Press any key to continue . . .