函数的入口地址(首地址):函数名
一、指针函数:指针函数实质是一个函数,其返回值是一个指针,是一个地址。
定义:type *function(type A,type B);
例:int *fun(int a,float c);
#include "stdio.h" static int *fun(int a,int b); // 指针函数 int *fun(int a,int b) { return a<b?a:b; } int main() { int a=500; int b=1000; int res1=fun(a,b); int res2=fun(b,a); printf("%d,%d\n",res1,res2); return 0; }
二、指针数组:指针数组实质是一个数组,数组里面储存的是指针。
定义:type *array[Num];
例:char *array[10];
#include "stdio.h" char array[][4]={1,2,3,4,5,6,7,8,9,10,11,12}; char *arr1[3]; int main() { char i=0; char j=0; for(;i<3;i++){ arr1[i]=array[i]; } i=0; for(;i<3;i++){ for(j=0;j<4;j++){ printf("%d ",arr1[i][j]); } printf("\n"); } return 0; }
三、函数指针:函数指针其实质就是一个指针,函数指针指向一个函数的首地址。
定义:1、type (* function)(type, type);
2、type (* function)(type A,type B);
例:int (* fun)(char *,float) ;或 int (* fun)(char *name,float sum);
#include "stdio.h" typedef int (*Calc)(unsigned char,unsigned char); // 定义一个函数指针 static int getValue(unsigned char a,unsigned char b); int getValue(unsigned char a,unsigned char b) { return a+b; } int (*t)(unsigned char,unsigned char); // 函数指针声明 int (*tt)(unsigned char a,unsigned char b); // 函数指针声明 int main() { unsigned char a=200; unsigned char b=250; t=getValue; tt=getValue; Calc sum=getValue; // 和 typedef struct相似。 printf("the sum is:%d\n",sum(a,b)); printf("the sum is:%d\n",t(a,b)); printf("the sum is:%d\n",tt(a,b)); return 0; }
四、数组指针:数组指针实质是指针,指向一个数组。
定义:type (*array)[Num];
例:char (*array)[10];
#include "stdio.h" char array[][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int main() { char i=0; char j=0; char (*ptr)[4]; ptr=array; for(;i<3;i++){ for(j=0;j<4;j++) printf("%d ",ptr[i][j]); printf("\n"); } return 0; }
函数指针数组:
原文:https://www.cnblogs.com/ligei/p/12431032.html