Reputation: 89
Can anyone explain this line of code in C :
void (*f)(void)= &fs ;
I tried to look in google for an explanation but i didn't find anything about it.
Upvotes: 0
Views: 3480
Reputation: 134286
I put the same statement in cdecl and its shows me
declare
f
as pointer to function(void)
returningvoid
.
That is it!! In other words, here, we define a variable f
of type as a pointer-to-a-function which accepts no arguments, ((void)
) and returns a void
, too. We are initializing the variable with the address of another function fs
, so that, f
points to the fs
function and can be used to call / invoke fs
.
Upvotes: 2
Reputation: 1439
It is defining a variable 'f' that is a function pointer which points to the function 'fs'. 'fs' is a function that takes no arguments are returns nothing so it might look like:
void fs(void) { printf("in fs"); }
If you ran the following code after the line in your question
(*f)();
It would call 'fs' and you would get a print out of "in fs"
Upvotes: 3