...
In this example, the function pointer fp
is used to refer to the function strchr()
. However, fp
is declared without a function prototype. As a result, there is no type checking performed on the call to fp(12,2);
. A typedef is included for compatibility with DCL05-C. Use typedefs to improve code readability.
Code Block | ||
---|---|---|
| ||
#include <stdio.h>
#include <string.h>
typedef char *(*fp) ();
int main(void) {
char *c;
fp = strchr;
c = fp(12, 2);
printf("%s\n", c);
return 0;
}
|
...
Code Block | ||
---|---|---|
| ||
#include <string.h>
typedef char *(*fp) (const char *, int);
int main(void) {
char *c;
fp = strchr;
c = fp("Hello",'H');
printf("%s\n", c);
return 0;
}
|
...