Previous: , Up: Function Pointers   [Index]

3.6.6 Function Pointers Examples

Pointer to function returning integer and having two integer parameters declaration:

    integer (*f1)(integer, integer);

Assigning it from function:

    f1 = max;

See The Function Pointer Assignment Operator.

Another function pointer declaration, of the same traits:

    integer (*f2)(integer, integer);

Assigning function pointer from function pointer:

    f1 = f2;


    f1 = f1;

Function call, through function pointer:

    f1(13, 16);

Function with function pointer parameter declaration:

fxxx(integer (*fp)(integer, integer), integer a, integer e)

call with function pointer argument:

    fxxx(f1, 13, 16);

and call with function argument:

    fxxx(min, 13, 16);

Function returning function pointer definition:

void (*exxx(integer select))(text)
    void (*fp)(text);

    if (select) {
	fp = o_text;
    } else {
	fp = o_etext;

    return fp;

Its trivial call:


Assigning function pointer with function return:

    fq = exxx(0);

where ‘fq’ was declared as:

    void (*fq)(text);

Function call via function pointer return:

    exxx(2)("function star program");

Assignment and call from function pointer return:

    (fq = exxx(2))("function star program");

Function with pointer to function parameter declaration, the parameter function having itself a pointer to function parameter:

gxxx(integer (*fp)(integer (*)(integer, integer), integer, integer),
     integer a, integer e)

Function returning pointer to function returning pointer to function definition:

void (*(*hxxx(void))(integer select))(text)
    return exxx;

and its call:

    hxxx()(0)("function star program");