1、函数指针:关键字在后面,是一个指针,指向一个函数。例如:
int max(int x,int y){
return x > y ? x : y;
}
int main(int argc,char **argv){
int (*p)();
int x = 4,y = 5;
p = max;
printf("%d\n",p(x,y)); //输出5
return 0;
}
2、指针函数:关键字在后面,是一个函数,返回类型为指针。例如:
char *Int_malloc(int size){
char *p = NULL;
p = (char *)malloc(size);
if(p == NULL)
perror("malloc");
return p;
}
int main(int argc,char **argv){
char *ptr = NULL;
ptr = Int_malloc(10);
strcpy(ptr,"abc");
printf("%s\n",ptr);
free(ptr);
return 0;
}