参考链接:
函数指针和指针函数用法和区别_luoyayun361的专栏-CSDN博客_指针函数
指针函数与函数指针(C语言) - 简书
指针函数:指针函数_百度百科
# include <stdio.h>
# include <string.h>
# include <iostream>
using namespace std;
float* find(float(*pionter)[4], int n);//函数声明
int main(void)
{
static float score[][4] = { {60,70,80,90},{56,89,34,45},{34,23,56,45} };
float* p;
int i, m;
printf("Enter the number to be found:");
scanf_s("%d", &m);
printf("the score of NO.%d are:\n", m);
p = find(score, m - 1);
for (i = 0; i < 4; i++)
printf("%5.2f\t", *(p + i));
return 0;
}
//形参pointer是指针指向包含4个元素的一维数组的指针变量
float* find(float(*pionter)[4], int n)/*定义指针函数*/
{
float* pt;
pt = *(pionter + n);
return(pt); //pt是一个指针变量,它指向浮点型变量。
}
函数指针:函数指针_百度百科
#include<stdio.h>
int max(int x, int y) { return (x > y ? x : y); }
int main()
{
int (*ptr)(int, int);
int a, b, c;
ptr = max;
scanf_s("%d%d", &a, &b);
c = (*ptr)(a, b);
printf("a=%d, b=%d, max=%d", a, b, c);
return 0;
}
|