For passing a function as a parameter, we are using a parameter s to be a pointer *s to the function similargeeks and that returns void type. so whenever we declare a pointer as a parameter to that array values are given to it as pointer.
#include <stdio.h>
void print(int n)
{
printf("%d ", n);
}
void similargeeks(void (*s)(int))
{
for(int i = 0; i < 5; i++)
{
(*s)(i);
}
}
int main(void)
{
similargeeks(print);
return 0;
}
0 1 2 3 4
In above example , similargeeks is declared with parameters with pointer and another function print is declared . similargeeks(print) ,by calling it acts as a pointer to print function.
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Also read: