LangProc / langproc-2018-cw

5 stars 4 forks source link

function pointers #32

Open BenShen98 opened 5 years ago

BenShen98 commented 5 years ago

Do we need to implement function pointer?

such as code below from Wikipedia

#include <stdio.h>  /* for printf */
#include <string.h> /* for strchr */

double cm_to_inches(double cm) {
    return cm / 2.54;
}

// "strchr" is part of the C string handling (i.e., no need for declaration)
// See https://en.wikipedia.org/wiki/C_string_handling#Functions

int main(void) {
    double (*func1)(double) = cm_to_inches;
    char * (*func2)(const char *, int) = strchr;
    printf("%f %s", func1(15.0), func2("Wikipedia", 'p'));
    /* prints "5.905512 pedia" */
    return 0;
}
johnwickerson commented 5 years ago

Nope.