what is a function pointer and how all to declare ,define
and implement it ???

Answer Posted / satish

Function pointer:
a function can be called not only by
its name,but also by other name which is called function
pointer.

void fact(int);
void main()
{
void(*p)(int);
printf("Enter n\n");
scanf("%d",&n);
p=fact;
fact(n);/*normal calling a function*/
(*p)(n); /*fn calling using function pointer*/

}
void (*p)(int n)
{
int ans=1;
while(n>0)
{
ans*=n--;
}

printf(" %d != %d",n,ans);

Is This Answer Correct ?    3 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If fflush wont work, what can I use to flush input?

589


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1470


what is the different bitween abap and abap-hr?

1714


What is character constants?

687


Why doesnt this code work?

598






What is exit() function?

540


Do variables need to be initialized?

599


which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

2348


How to write a multi-statement macro?

598


Why we use void main in c?

566


What is typeof in c?

579


What are local static variables?

599


Explain how can I prevent another program from modifying part of a file that I am modifying?

615


Tell me when would you use a pointer to a function?

573


What is default value of global variable in c?

533