指针函数与函数指针

来源:互联网 发布:ipad 电容笔 知乎 编辑:程序博客网 时间:2024/06/03 02:17

学数据结构用到了指针函数,查阅资料作个总结.

1.指针函数

顾名思义,就是一个带有指针的函数,本质是一个函数。返回值为某一类型的指针。

举例:

#include <stdio.h> 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("%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; } float *find(float(*pionter)[4],int n)/*定义指针函数*/ {     float *pt;     pt=*(pionter+n);     return(pt); }

find 返回了一个指针

2.函数指针即为指向函数的指针变量,其本质为指针。

举例:

#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("%d%d", &a, &b);    c = (*ptr)(a,b);    printf("a=%d, b=%d, max=%d", a, b, c);    return 0;}
此例利用了指针来接收返回值。

0 0
原创粉丝点击