I found this problem in a book.
Problem:
What is the output of the following program ?
#include <stdio.h>
int fun(int,int);
typedef int(*pf) (int,int);
int proc(pf,int,int);
int main()
{
printf("%d\n",proc(fun,6,6));
return 0;
}
int fun(int a,int b){
return (a==b);
}
int proc(pf p,int a,int b){
return ((*p)(a,b));
}
This code, when run, prints out 1.
I tried understanding it but no it is of no use. What is going in this program and why does it output 1?
Thanks in advance.
procis indirectly callingfunvia a function pointer. The arguments thatfunreceives are again6and6, and the equality operator evaluates to anintwith the value1because they are equal. If they were not equal, the==operator would yield0.