CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
When would you use a pointer to a function?
Category C Interview Questions
Rating (5.0) By 19 users
Added on 10/22/2004
Views 3836
Rate it!
Answers:

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. 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.





If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Why should we assign NULL to the elements (pointer) after freeing them?
View Answer
Is it better to use malloc() or calloc()?
View Answer
What is the difference between far and near?
View Answer
When should a far pointer be used?
View Answer
Can the size of an array be declared at runtime?
View Answer
What is the heap?
View Answer
What is the difference between NULL and NUL?
View Answer
What is a ?null pointer assignment? error? What are bus errors, memory faults, and core dumps?
View Answer
How can you determine the size of an allocated portion of memory?
View Answer
Can math operations be performed on a void pointer?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/1003/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.83