NEW INTERVIEW QUESTIONS.COM
LANGUAGES INTERVIEW QUESTIONS
C INTERVIEW QUESTIONS DETAILS
NewInterviewQuestions.com - Home for World's Largest Interview Questions Website.
A D V E R T I S E M E N T
Question |
How do you use a pointer to a function? |
Answer
|
The hardest part about using a pointer-to-function is declaring it.
Consider an example. You want to create a pointer, pf, that points to the strcmp() function.
The strcmp() function is declared in this way:
int strcmp(const char *, const char * )
To set up pf to point to the strcmp() function, you want a declaration that looks just like the strcmp() function?s declaration, but that has *pf rather than strcmp:
int (*pf)( const char *, const char * );
After you?ve gotten the declaration of pf, you can #include <string.h> and assign the address of strcmp() to pf: pf = strcmp;
© NewInterviewQuestions.com
|
If you have the better answer, than send it to us. We will display your answer after the approval.
Rate the above answer. Help us to know about the answer.
Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.
A D V E R T I S E M E N T
|