永发信息网

谁能给一个使用复杂声明“char*(*p[2])(const char*,const char*)的程序

答案:1  悬赏:80  手机版
解决时间 2021-04-03 23:12
  • 提问者网友:萌卜娃娃
  • 2021-04-03 15:10
谁能给一个使用复杂声明“char*(*p[2])(const char*,const char*)的程序
最佳答案
  • 五星知识达人网友:夜风逐马
  • 2021-04-03 15:27
char*(*p[2])(const char*,const char*)声明了一个长度为2的指针数组,该数组的元素类型是有两个const char*型的参数,返回类型为char *的函数指针。

#include
#include
#include

char *f1(const char *a,const char *b)
{
char *temp=(char *)malloc(1+strlen(a)+strlen(b));
strcpy(temp,a);
strcat(temp,b);
return temp;
}

char *f2(const char *a,const char *b)
{
char *temp=(char *)malloc(1+strlen(a)+strlen(b));
strcpy(temp,b);
strcat(temp,a);
return temp;
}

void main()
{
char*(*p[2])(const char*,const char*);
int n;
char a[81],b[81];
p[0]=f1;p[1]=f2;
printf("输入字符串a,以回车结束");
gets(a);
printf("输入字符串b,以回车结束");
gets(b);
printf("输入数字0或1");
scanf("%d",&n);
printf("%s\n",p[n](a,b));
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯