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 is && in c programming?

0 Answers  


what is the difference between declaration ,defenetion and initialization of a variable?

7 Answers   LG Soft,


find out largest elemant of diagonalmatrix

0 Answers  


print out put like this form 1 2 3 4 5 6 3 5 7 9 11 8 12 16 20

8 Answers   TCS,


write a program to print sum of each row of a 2D array.

4 Answers  


program to convert a integer to string in c language'

0 Answers  


What are valid operations on pointers?

0 Answers  


What is the use of a conditional inclusion statement in C?

0 Answers   Global Logic,


What happens if header file is included twice?

0 Answers  


How can I convert integers to binary or hexadecimal?

2 Answers  


Write a program of prime number using recursion.

0 Answers   Aspiring Minds,


What is a spanning Tree?

1 Answers   TCS,


Categories