Results 1 to 4 of 4

Thread: Passing function pointer as argument

  1. #1
    Join Date
    Mar 2008
    Posts
    672

    Passing function pointer as argument

    I read the tutorial on function pointers, the arguments of the declaration of the pointer is not clear. The following code does not work :
    Code:
    # include <stdio.h> 
      int (int a, int b)
     (
         return a * b;
     )   
     
      int (int c, int d)
     (
         return c / d;
     )
     
     int main ()
     (
         int a = 20;
         int b = 20;
         int d = 100;
       
         int (* p) (int, int) = NULL;
         p = & function2;
       
         int (* p2) (int, int) = NULL;
         p2 = & function3;
       
         int (* t [2]) () = (p (a, b), p2 (p (a, b), d)) 
     
         printf ( "Result:% d \ n", (* p) (a, b));
         printf ( "Result:% d \ n", (* p2) (p (a, b), d));
       
         printf ( "\ n");
       
         printf ( "Result:% d \ n", t [0 ]()); 
         printf ( "Result:% d \ n", t [1 ]());   
       
         getchar ();
         return 0;
     )

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Passing function pointer as argument

    By cons libraries function that you can do...
    Code:
    void func (int x, int y);
    
     boost:: function <void (int) f = boost:: bind (& func, 5);
     f (6) / / calls func (5, 6)

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Passing function pointer as argument

    Code:
    #include <string.h>
    #include <stdlib.h>
    
    void func(int (*comp)()) {
        char *g="123";
        char *f="234";
        if( comp(g,f)!=0 ) { 
            printf("pointer");    
        }
    }
    
    int main() {
      
      func( strcmp );
    
      return EXIT_SUCCESS;
    }

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Passing function pointer as argument

    Passing a function pointer as an argument to a function is quite essential when you want to implement callback functions. Passing function pointers to a DLL has been done for generations.A function pointer is a variable that stores the address of a function that can later be called through that function pointer.

Similar Threads

  1. Passing XSL value to javascript function
    By Steadfast in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:51 PM
  2. Pointer parameter in a function
    By Chrisch in forum Software Development
    Replies: 4
    Last Post: 14-12-2009, 10:57 PM
  3. Passing arguments to a function
    By Aman 1 in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 01:11 PM
  4. Passing function parameter and static
    By Banjiji in forum Software Development
    Replies: 3
    Last Post: 27-10-2009, 07:32 PM
  5. Problem in a function pointer
    By Rilex in forum Software Development
    Replies: 3
    Last Post: 23-05-2009, 10:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,033,149.02566 seconds with 17 queries