函数指针:指向函数的指针,实例:求几个数数中的最大值

#include <stdio.h>

// 求两个数中的最大值
int max(int x, int y)
{
	return x > y ? x : y;
}

int main()
{
	int (*ptr)(int, int) = &max;	// 函数指针:指向函数的指针
	int a, b, c, d;

	printf("请输入三个数字:(以空格键隔开)");
	scanf("%d %d %d", &a, &b, &c);

	d = ptr(ptr(a, b), c);

	printf("最大数是:%d", d);

	// 结束main函数
	return 0;
}

 

 

posted @ 2018-02-21 09:27  半生戎马,共话桑麻、  阅读(240)  评论(0)    收藏  举报
levels of contents