PRODUCT : Borland C++ NUMBER : 1152 VERSION : 3.1 OS : ALL DATE : October 19, 1993 PAGE : 1/2 TITLE : Example of function returning pointer to function. This is an example demonstrating a function that returns a pointer to a function. /* This is an example demonstrating a function that returns a pointer to a function. Expected output should be in bar() A comes before B */ #include /* funcptr is a pointer to a function that takes a single argument of type char and returns nothing. */ typedef void (*funcptr)( char ); /* foo is a function takes a single argument of type char and returns nothing. */ void foo( char letter ) { printf( "%c comes before %c\n", letter, letter + 1 ); } /* bar is a function that takes no arguments and returns a pointer to a function that takes a single argument of type char and returns nothing. */ funcptr bar( void ) { printf( "in bar()\n" ); PRODUCT : Borland C++ NUMBER : 1152 VERSION : 3.1 OS : ALL DATE : October 19, 1993 PAGE : 2/2 TITLE : Example of function returning pointer to function. return foo; } void main( void ) { /* Line B below is equivalent to: void (*f)(char) = bar(); Thus, f is a pointer to a function X that takes one argument of type char and X returns a pointer to a function of type void (*)(int). Note that f doesn't point to the function bar(); it points to what bar() returns. */ /* Line A is equivalent to Line B */ /* void (*f)(char) = bar(); */ /* Line A */ funcptr f = bar(); /* Line B */ /* Now call the function that f points to. Since f points to function foo(), which takes a single argument of type char, we want to pass it a single char argument. */ f('A'); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.