|
INTERVIEW QUESTIONS
C
FUNCTIONS IN C
DETAILS
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 and assign the address of strcmp() to pf: pf = strcmp;
|
|
|
Category |
Functions in C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7824 users |
Added on |
9/18/2014 |
Views |
70066 |
Rate it! |
|
|
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 and assign the address of strcmp() to pf: pf = strcmp; Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Is it possible to execute code even after the program exits the main() function?
|
View Answer
|
|
Does there exist any other function which can be used to convert an integer or a float to a string ?
|
View Answer
|
|
Advantages of a macro over a function ?
|
View Answer
|
|
What is the difference between printf() and sprintf() ?
|
View Answer
|
|
What is the code for clrscr() function?
|
View Answer
|
|
How to use the cprintf,cscanf,sscanf,sprintf,vsscanf,vsprintf,vscanf & vprintf?
|
View Answer
|
|
How to convert decimal to octal and hexadecimal in c program?
|
View Answer
|
|
How to use floodfill() function and what is the use of kbhit?
|
View Answer
|
|
Write a program with out using main() function?
|
View Answer
|
|
Can there be at lest some solution to determine the number of arguments passed to a variable argument list function?
|
View Answer
|
|
What do the functions atoi(),itoa()and gctv()do?
|
View Answer
|
|
How would you use bsearch()function to search a name stored in array of pointers to string?
|
View Answer
|
|
How would you use the functions sin(),pow(),sqrt()?
|
View Answer
|
|
how would you use the functions memcpy(),memset(),memmove()?
|
View Answer
|
|
How would you use the functions randomize()and random()?
|
View Answer
|
|
How would you use the functions randomize()and random()?
|
View Answer
|
|
what is the difference between the functions rand(),random(),srand() and randomize()?
|
View Answer
|
|
Can you use the function fprintf()to display the output on the screen?
|
View Answer
|
|
How to see return value of main function?
|
View Answer
|
|
How to write a program in c to print its own code?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Functions in C Interview Questions & Answers - Exam Mode /
Learning Mode
|