0
点赞
收藏
分享

微信扫一扫

函数指针数组

40dba2f2a596 2022-01-04 阅读 59
c语言

#include "stdio.h"

void TheShow()
{
    printf("1.xiao\n");
}
void Zootopia()
{
    printf("2.feng\n");
}

void Inteste()
{
    printf("3.xing\n");
}

void TheLegendof()
{
    printf("4.hai\n");
}

void TheMatrix()
{
    printf("5.hei\n");
}

int main()
{
    void(*p[5])()={TheShow,Zootopia,Inteste,TheLegendof,TheMatrix};
    char list[20];
    scanf("%s",list);
    
    for (int i=0;list[i]!='\0';i++)
    {
        char num=list[i];
        num=num-'0';
        num--;
        (*p[num])();        //可简化为,p[num]();,c语言支持这两种书写方式
    }
    
    
    return 0;
};


 

举报

相关推荐

函数指针和函数指针数组

0 条评论