How do you initialize function pointers? Give an example?

Answers were Sorted based on User's Feedback



How do you initialize function pointers? Give an example?..

Answer / vadivel t

Initialisation can be done in the following way.

func(int a,int b);
*pfunc(int a, int b);
main()
{

/*here the starting address of the function can be assigned
to a function pointer of the same type*/
pfunc = func;
....
....
....
}
func(int a, int b)
{
....
....
....
}

Is This Answer Correct ?    1 Yes 0 No

How do you initialize function pointers? Give an example?..

Answer / preeti singh

for e.g. if we have to declare a pointer to a function , the
signature of which is :
int add(int a,int b)

then a pointer to the above function can be declared as:
int (*myptr)(int ,int);

here myptr is a pointer which can point to any function that
takes 2 int args and returns an int value.

Is This Answer Correct ?    1 Yes 1 No

How do you initialize function pointers? Give an example?..

Answer / vadivel t

Sorry the above function pointer declaration should be like
this

(*pfunc)(int, int);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What are the 32 keywords in c?

0 Answers  


Wt are the Buses in C Language

0 Answers   Infosys,


no consistent academics. how to answer the question

0 Answers  


How arrays can be passed to a user defined function

0 Answers  


In C program, at end of the program we will give as "return 0" and "return 1", what they indicate? Is it mandatory to specify them?

5 Answers  






What is the difference b/w main() in C language and main() in C++.

7 Answers  


any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above

0 Answers  


What are the two types of functions in c?

0 Answers  


HOW CAN ADD OUR FUNCTION IN LIBRARY.

5 Answers  


how to add numbers without using arithmetic operators.

14 Answers   TCS,


What is a structural principle?

0 Answers  


When should the register modifier be used? Does it really help?

0 Answers  


Categories