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

WHO WROTE C LANGUAGE?

4 Answers  


who is the father of C Language?

20 Answers   CTS, UST,


C passes By value or By reference?

5 Answers   Geometric Software, Infosys,


How can I invoke another program or command and trap its output?

1 Answers  


What is structure padding ?

3 Answers   HP,


Do variables need to be initialized?

1 Answers  


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

1 Answers   Amdocs, Apps Associates,


What is a class?

3 Answers  


write a program to insert an element at the specified position in the given array in c language

5 Answers   Appin, IBM,


What are the differences between Structures and Arrays?

1 Answers   TCS,


What is the difference between char a[] = "string"; and char *p = "string"; ?

14 Answers   Adobe, Honeywell, TCS,


How many main () function we can have in a project?

1 Answers  


Categories