2

I am trying to understand all this HUGE concept of function pointers...

Is it possible to initalize function pointer with non-declared function?

For example, a simple use of function pointer would be:

void f()
{
  printf("Hello world!");
}
//Somewhere in the program
void (*foo)();
foo = &f;

Is there any way to skip the declaration of f? something like that:

void (*foo)();
foo = { printf("Hello world!"); }
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
I1265
  • 51
  • 6

1 Answers1

4

What you describe are called lambda functions, a mechanism which is not available in C. You can think of lambda functions as anonymous functions.

C++ and C# support that. Read more in .Function pointers, Closures, and Lambda

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
gsamaras
  • 71,951
  • 46
  • 188
  • 305