Search code examples
cprototypefunction-pointers

Passing a pointer to a function?


I want to achieve this code:

state(state);

So, first I declare a pointer to a function. I set the pointer to the start function. And the start function takes a pointer to a function also. I call the function using the state pointer, and pass the state pointer along for modification in start.

How do I properly declare the function pointer created in main, and how do I declare the prototypes?


Solution

  • Your intention isn't very clear but you can pass function pointers like this:

    int g ((*myfunc)(int x))
    {
     stuff for g;
     (*myfunc)(2);
    }
    
    int f (int a)
    {
     stuff for f;
    }
    
    main()
    {
     g (f);
    }