Could anyone explain the areas, where the Function Pointers are applied ? :rolleyes:
Thanks,
rssrik
Printable View
Could anyone explain the areas, where the Function Pointers are applied ? :rolleyes:
Thanks,
rssrik
Look at the prototypes for qsort() and bsearch() in stdlib.h
They're also commonly used to implement callback functions in GUIs.
Dynamically call functions, where you don't know which functions to call. Also, provide an effective means to allow others to replace functions.
For example, when a C program, when you return from main(), a function called exit() from stdlib.h is automatically called. This function cycles through some cleanup functions. You can register your own function to be called during this by giving a pointer to your particular function.
Also, in Windows programming, GUI objects all have a function pointer associated with them that handle events. You can give your own function pointer to have your own custom handling of these same events.
This allows you to "fake" OOP in C, which, in reality, is how C++ really handles OO concepts under the hood.
*fopen() used in file I/O
fopen() does not use function pointers (unless you're referring to some implementation or specific internal detail). It returns a pointer to an instance of a FILE struct.
A function pointer is a pointer that points to a function.
I just got out of bed... :D
understood somewhat !
to understand more, I request someone to post a code or link to illustrate the usage of function pointers !!
Regards,
rssrik
Search the forums for examples of use of qsort().
I've posted such examples many times already.