Subscribe:

Ads 468x60px

Wednesday, July 10, 2013

C++ Tips : Pointer to a Function

Program showing the usage of Function Pointer

 /*  
 name : main.cpp  
 Calling a function using function pointer  
 */  
 #include <stdio.h>  
 int main()  
 {  
      int display();  
      int (*func_ptr)();        ///Declare function Pointer  
      func_ptr = display;        /// Assign address of function  
      printf("\n Address of function display is %u", func_ptr);      ///Printing Address of function  
      (*func_ptr)();          /// Invokes the function display  
      getchar();            ///Get char for seeing the output  
      return 0;  
 }  
 int display()  
 {  
      puts("\n Hello World !!\n");  
      return 1;  
 }  


Output
-------------



1 comments:

Post a Comment