Thread: Returning address of Function. Pointers to Functions.

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    19

    Returning address of Function. Pointers to Functions.

    Hi everybody,

    I am trying to assign an address of a function to a variable.
    How can I do this in C?

    Thanks!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    #include <stdio.h>
    
    int func(int a)
    {
    	return a;
    }
    
    typedef int(*MyFuncType)(int);
    
    int main()
    {
    	MyFuncType pFunc;
    
    	pFunc = func;
    	printf("%d", pFunc(5));
    	return 0;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    19
    Thank you!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Class function pointers
    By VirtualAce in forum C++ Programming
    Replies: 40
    Last Post: 02-17-2005, 12:55 AM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. function pointers and member functions
    By thor in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2002, 04:22 PM