I have a function which has a function pointer input. I can easily give function names to it as input. But I wonder if it's possible to define a function as input. For example I have a function like this;
void exampleFunction ( void (*functionPointer)( void ) ) {
codes
...
}
Can I give an input like this inside the brackets? For example;
exampleFunction( void helloFunction ( void ) {
printf("Hello");
} );
It gives compilation error like this but is there any other ways to do it?
This is impossible in C.
In C++, you can use a lambda-expression:
exampleFunction([](){ std::cout << "Hello"; });