Answer: </I>Pointers to functions are interesting when you pass them to other functions. A function that takes function pointers says, in effect, "Part of what I do can be customized. Give me a pointer to a function, and I'll call it when that part of the job needs to be done. That function can do its part for me." This is known as a "callback." It's used a lot in graphical user interface libraries, in which the style of a display is built into the library but the contents of the display are part of the application. As a simpler example, say you have an array of character pointers (char*s), and you want to sort it by the value of the strings the character pointers point to. The standard qsort() function uses function pointers to perform that task. (For more on sorting, see Chapter III, "Sorting and Searching Data.") qsort() takes four arguments, Ø a pointer to the beginning of the array, Ø the number of elements in the array, Ø the size of each array element, and Ø a comparison function, and returns an int.
Tags:Interview Questions, Languages, C,
Please submit your Interview Answer for the above Question via replying to this post. Thank you for visiting to our blog, Have a Good Day!.
Sponsor Advertisement
Library Management System Software
Our Library Management Softare offers complete library management modules and automation solution that enables information providers, information managers, resource incharge, resource managers & librarians to manage & disseminate information & resources....
No comments:
Post a Comment