why we need function pointers?

Answers were Sorted based on User's Feedback



why we need function pointers? ..

Answer / kirankumaryakkala

a pointer that holds the address of a function.
in writing the interrupt service routines(isr),memory virus
programs, etc..
as simply, if u wanna execute one function out of two or
more funcitons( the selection based dynamically)

ex. int add(int a, int b)
int sub(int a, int b)
int mul(int a, int b)

int (*ptr)(int a, int b) //function pointer declaration to
hold a function that takes two integers, returns one integer

here,
ptr= it can assign any function name that is going to execute


Is This Answer Correct ?    11 Yes 2 No

why we need function pointers? ..

Answer / naman patidar

Apart from above mentioned usage function pointer are used
by event listeners and callback utilities in multi threaded
applications.

Is This Answer Correct ?    3 Yes 0 No

why we need function pointers? ..

Answer / gajendra

Function Pointers are pointers, i.e. variables, which point to the address of a function. You must keep in mind,
that a running program gets a certain space in the main-memory. Both, the executable compiled program code
and the used variables, are put inside this memory.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

5 Answers   Vector, Vector Solutions,


What are pointers? What are different types of pointers?

0 Answers   Fidelity,


Prove or disprove P!=NP.

5 Answers   Microsoft,


write a c program to remove all the duplicate characters in a string and replace with single character? ex:-input- AAABBBCCC output- ABC

2 Answers   HCL,


How do you determine if a string is a palindrome?

1 Answers  


What are the uses of pre-processor directives?

2 Answers  


which will be first in c compiling ,linking or compiling ,debugging.

3 Answers   Sonata,


What is formal argument?

0 Answers  


Between macros and functions,which is better to use and why?

0 Answers  


When should we use pointers in a c program?

0 Answers  


What does %c mean in c?

0 Answers  


What are linked lists in c?

0 Answers  


Categories