/********函数指针***********/
int max(int a, int b) {
if (a > b) return a;
else return b;
}
int main() {
int max()(int a, int b);
int (*pmax)();
int x, y, z;
pmax = max;
printf("input two numbers:
");
scanf("%d%d", &x, &y);
z = (*pmax)(x, y);
printf("maxnum=%d", z);
return 0;
}
/******指针函数*********/
int main() {
int i;
char* day_name(int n);
printf("input day no:
");
scanf("%d", &i);
if (i < 0)
exit(1);
printf("day no: %2d-->%s
", i, day_name(i));
return 0;
}
char* day_name(int n) {
static char* name[] = {
"Illegal day",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
return (n < 1 || n > 7) ? name[0] : name[n];
}
/*****************************************/
int *p | p为指向整形变量的指针 |
int *p[n] | p为存放指针的数组(指针数组) |
int (*p)[n] | p为指向数组的指针(数组指针) |
int *p() | p为返回指针的函数(指针函数) |
int (*p)() | p为指向函数的指针(函数指针) |
int **p | p为指向指针的指针 |
int*(*(*a)())[10];//a是一个函数指针变量,该函数返回一个指针值,该指针值指向一个数组,该数组元素为int型指针。