Returning address of Function. Pointers to Functions.

This is a discussion on Returning address of Function. Pointers to Functions. within the C Programming forums, part of the General Programming Boards category; Hi everybody, I am trying to assign an address of a function to a variable. How can I do this ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,468
    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;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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-16-2005, 11:55 PM
  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, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21