返回指针的函数:
#include <stdio.h>
char *test();
int main()
{
char *name = test();
printf("name=%s\n", name);
return 0;
}
char *test()//表示指针函数
{
return "rose";//返回字符串
}
指向函数的指针:
1.看懂语法
2.定义指向函数的指针
double(*p) (double, char *, int);
p = haha;
或者
double (*p) (double, char *, int) = haha;
3.如何间接调用函数
1.p(10.7 “jack”, 10)
2.(*p) (10.7,“jack”, 10);
#include <stdio.h>
void test()
{
printf("调用了test函数\n");
}
int main()
{
//(*p)是固定写法,代表指针变量p将来肯定是指向函数
//左边的void:指针变量p指向的函数没有返回值
//右边的():指针变量指向的函数没有形参
void (*p)();
//指针变量p指向了test函数
p = test;
(*p)();//利用指针变量间接调用函数
p();//利用指针变量间接调用函数
return 0;
}