The program's output is:
1
Ok, so let's see what's going on there.
#include<stdio.h>
This line just include standard input/output functionality.
int fun(int, int);
This tells the compiler: Ok, we have a function named fun
taking two int
variables, returning an int
.
typedef int (*pf) (int, int);
This installs kinda shortcut for a pointer to a function taking two int
variables returning int
, so this kind of function pointer can be abbreviated using pf
.
int proc(pf, int, int);
Tells the compiler: Ok, we have a function named proc
taking a pf
variable (which is - like we saw above - a function pointer to a function taking two int
variables returning an int
), two int
variables, returning an int
.
int main()
{
printf("%d\n", proc(fun, 6, 6));
return 0;
}
The central procedure that's run when the program is executed. It tells the program to print a number (%d
) and a newline (\n
). The number shall have the value of proc(fun,6,6)
.
int fun(int a, int b)
{
return (a==b);
}
Here we have what function fun
is supposed to do. This function compares a
and b
, returns 1 if they're equal, 0 otherwise (just the definition of results of ==
in C).
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
Here we have what proc
actually does: It takes a function pointer (which is - as we saw above - ...) p
and two ints. Then it calls the given function (p
) applied to the two arguments given (a
and b
) and returns p
's result.
So, if we call proc(fun, 6, 6)
, proc
will call fun(6,6)
, which evaluates to 1 (since 6==6
) and returns this result (1
).
So, the output will be just
1
But honestly: Please have a look at some things and try to figure out things yourself before just asking (why is the output this-and-that):