User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,473 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,928 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums

what is pointer to function ???

Join Date: Jul 2005
Posts: 75
Reputation: CrazyDieter is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
CrazyDieter's Avatar
CrazyDieter CrazyDieter is offline Offline
Junior Poster in Training

Re: what is pointer to function ???

  #2  
Jul 4th, 2006
Originally Posted by joshilay
can anyone tell me what are pointers to function ??? and how are they implemented ??


in C, functions are defined just like variable.

The adress of a function can be assimiled to its adress in memory, so the following code is valid :
#include <stdio.h>


void something()
{
    printf("hello\n");
}


void somethingElse()
{
    printf("hello2\n");
}

int main(void)
{
   (void)(*pointer)() = something;

   pointer();
   
   pointer = somethingElse;

   pointer();

    return 0;
}
Last edited by CrazyDieter : Jul 4th, 2006 at 2:27 pm.
Reply With Quote  
All times are GMT -4. The time now is 4:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC