Link: http://www.cnblogs.com/super119/archive/2011/03/26/1996145.html
A question from interview, so I wrote a test program to demonstrate.
Func is a function pointer. the return value of this function is int without any input parameters. Then, the main program declares a function pointer myfuncpointer, which indicates that the input parameter of the function pointer represents an int, the return value is also a function pointer, And the type is func type. So we can assign the func2 function to the pointer of myfuncpointer. The question of interview is the declaration of myfuncpointer.
# Include <stdio. h>
Typedef int (* func )();
Int func3 ()
{
Printf ("in function 3.../N ");
Return 0;
}
Func func2 (int)
{
Printf ("input parameter is: % d/N", );
Return func3;
}
Int main ()
{
Func (* myfuncpointer) (INT) = func2;
Func returnvalue = myfuncpointer (1111 );
Int func3_return = returnvalue ();
Printf ("func3 return value is: % d/N", func3_return );
Return 0;
} Original article link: Workshop
# Include <stdio. h>
Int get_big (int I, Int J)
{
Return I> = J? I: J;
}
INT (* F (int A) (INT, INT) // F (int A) is a function. The return value of this function is
{// Pointer to the function (the return value of this function is int and has two int-type parameters)
Printf ("A = % d/N", );
Return get_big;
}
Int main (void)
{
Int Max;
INT (* p) (INT, INT); // defines a pointer pointing to a function (the return value of this function is int, and two of them are int parameters ).
P = f (100 );
Max = P (5, 8 );
Printf ("max = % d/N", max );
Return 1;
}