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

Write a function in c to find the area of a triangle whose length of three sides is given.

2 Answers  


please send me the code for multiplying sparse matrix using c

0 Answers  


wat is the difference between a definition and declaration? float y;---it looks like a declaration..but it s a definition.how?someone explain

3 Answers   TCS,


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

0 Answers   Wilco,


Can u return two values using return keyword? If yes, how? If no, why?

7 Answers  


How to write a code for reverse of string without using string functions?

0 Answers   TCS,


Write a program of prime number using recursion.

0 Answers   Aspiring Minds,


write a prgram of swapping with 2 valiables

6 Answers  


write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

0 Answers   TCS,


program for following output using for loop? 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5

8 Answers   Infosys,


program in c to print 1 to 100 without using loop

9 Answers   Wipro,


How main function is called in c?

0 Answers  


Categories