Function pointers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Subha Ramanathan
    New Member
    • Nov 2006
    • 1

    Function pointers

    Sir/Mam,
    I am a beginner in C language ,Can you say me what is the difference between an ordinary function and a function pointer.How function pointer is advantageous over normal functions.

    Thanks
    Subha
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Well I function is a function.

    A function pointer is not a function at all, it is a variable containing the location of a function.


    Function pointers are useful when you wish to be able to pass a function to another piece of code so that it can call the function provided. A general example of this is callback functions, you call a function with some data including a pointer to a function. Under certain circumstances the called function then calls the function you have provided a pointer to.

    A specific example of this is qsort. qsort sorts any array given the number of elements and the size of the elements in the array and a pointer to a comparison function.

    Comment

    Working...