446 views
0 votes
0 votes
Since we know that In function,the function name itself can act as the address to the function just like it was happening in array.

 

So the given below program is correctly working:-

 

#include<stdio.h>

int sum(int x,int y)

{

return x+y;

}

int (*fb)(int,int);

int main()

{

  fb=sum; // I will modify here

  printf("%d",fb(8,6));

}

Output:-14

 

But when I am doing just a one modification on modification line as

fb=&sum;

 then also the program is correctly working as shown below:-

#include<stdio.h>

int sum(int x,int y)

{

return x+y;

}

int (*fb)(int,int);

int main()

{

  fb=&sum; //modified here

  printf("%d",fb(8,6));

}

Output:- 14

How this is happening?

And then also when I am modifying in printf then also it is working as shown below:-

#include<stdio.h>

int sum(int x,int y)

{

return x+y;

}

int (*fb)(int,int);

int main()

{

  fb=&sum;

  printf("%d",(*fb)(8,6));

}

Output:- 14

 

So from the above I am seeing that

fb=sum; or fb=&sum; both are equivalent

 and (*fb)(8,6) and (fb)(8,6) are equivalent.

How this is happening?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
2
Nishi Agarwal asked Mar 10, 2019
512 views
A(n){if(n<1) return (1);else return A(n-2)+B(n-1);}B(n){if(n<=1) return 1;else return B(n-1)+A(n-2);}