/*
a) int a; //An integer
b) int *a; //A pointer to an integer
c) int **a; //A pointer to a pointer to an integer
d) int a[10]; //An array of 10 integers
e) int *a[10]; //An array of 10 pointers to integers
f) int (*a)[10]; //A pointer to an array of 10 integers
g) int (*a)(int); //A pointer to a function a that takes
an integer argument and returns an integer
h) int (*a[10])(int); //An array of 10 pointers to functions that
take an integer argument and return an integer
*/
#include <stdio.h>
#include <stdlib.h>
#include < string.h>
//指向函数指针有三个用途:调用函数、数组、做函数的参数。
char* strCompare( char *str1, char *str2){ //每一个函数都有一个入口地址
return (strcmp(str1, str2) > 0) ? str1 : str2;
}
char* strMaxLength( char *str1, char *str2){
return strlen(str1) > strlen(str2) ? str1 : str2;
}
int main( int argc, char** argv) {
char *str1 = "Hello Stone River", *str2 = "Hello World", *result1, *result2;
char* (*strMax)( void *, void *); //指向函数的指针变量
strMax = strCompare;
result1 = strMax(str1, str2);
strMax = strMaxLength;
result2 = strMax(str1, str2);
printf( "result1 = %s, result2 = %s\n", result1, result2);
//指针数组,每个数组元素是一个指针变量,将指向一个函数
char* (*strMaxArray[2])( void *, void *);
strMaxArray[0] = strCompare;
strMaxArray[1] = strMaxLength;
printf( "result1 = %s, result2 = %s\n",
strMaxArray[0](str1, str2), strMaxArray[1](str1, str2));
return (EXIT_SUCCESS);
}