Functions as parameters in C -
i'm working on project intro c class, creating hash table implementation in c current question pertains how function written in code skeleton provided professor. here header definition of create method:
table* create(long (*hash)(void* key), bool (*equals)(void* key1, void* key2), void (*print)(void* key1, void* key2));
this appears pointers functions parameters? i'm not sure how call this, or happens when called. i'm not sure these methods (hash, equals, , print) coming from. appreciated. thanks
this appears pointers functions parameters?
yes.
i'm not sure how call this
to invoke function create
, pass addresses of functions right types call create
:
create(&f1, &f2, &f3);
or happens when called.
any place in body of create
where(*) pointed function invoked, actual function (for instance f1
) ends being called provided arguments. (*equals)(k1, k2);
fictional example have occurred inside create
.
(*) or, in case, function function pointers struct allocated create
have stored them
in fact c allows write create(f1, f2, f3);
in first case , equals(k1, k2);
in second, that's convenience.