当前位置:网站首页>函数指针数组
函数指针数组
2022-08-03 09:30:00 【smith342】
第一次使用函数指针数组
#include<stdio.h>
void Monday_fun()
{
printf("Monday");
}
void Tuesday_fun()
{
printf("Tuesday");
}
void Wednesday_fun()
{
printf("Wednesday");
}
void Thursday_fun()
{
printf("Thursday");
}
void Friday_fun()
{
printf("Friday");
}
void Saturday_fun()
{
printf("Saturday");
}
void Sunday_fun()
{
printf("Sunday");
}
int main()
{
int day;
printf("Please input the day of week:\n");
scanf("%d",&day);
/*
switch (day)
{
case 1:
Monday_fun();
break;
case 2:
Tuesday_fun();
break;
case 3:
Wednesday_fun();
break;
case 4:
Thursday_fun();
break;
case 5:
Friday_fun();
break;
case 6:
Saturday_fun();
break;
case 7:
Sunday_fun();
break;
default:
break;
}
*/
void (*weekday[7])();
weekday[0]=Monday_fun;
weekday[1]=Tuesday_fun;
weekday[2]=Wednesday_fun;
weekday[3]=Thursday_fun;
weekday[4]=Friday_fun;
weekday[5]=Saturday_fun;
weekday[6]=Sunday_fun;
weekday[day-1](); //必须要加(),不然只是指针,没有调用函数
return 0;
}边栏推荐
- Rabbit and Falcon are all covered, Go lang1.18 introductory and refined tutorial, from Bai Ding to Hongru, the whole platform (Sublime 4) Go lang development environment to build EP00
- Flink Yarn Per Job - 创建启动Dispatcher RM JobManager
- 批量将PNG格式转化为JPG格式
- 015-Balanced binary tree (1)
- Index (3)
- MySQL-DDL数据定义语言-约束
- STP生成树选举结果查看及验证
- Oracle数据库表空间整理回收与释放操作
- 013-Binary tree
- dflow部署简记
猜你喜欢
随机推荐
cert-manager使用
Path Prefixes (倍增!树上の二分)
2022最新整理软件测试常见面试题附答案
面试突击71:GET 和 POST 有什么区别?
【无标题】
dflow入门5——Big step & Big parameter
dflow入门1——HelloWorld!
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
STP生成树(端口状态+端口角色+收敛机制 )|||| STP优化技术( uplinkfast技术+Portfast技术+backbonefast技术 )详解
The display of the article list and the basics of creating articles and article details
"Easy to use" websites that others don't know, make you more efficient
分区分表(一)
【LeetCode】226.翻转二叉树
Redis实现分布式锁
Scala parallel collections, parallel concurrency, thread safety issues, ThreadLocal
多线程下的单例模式
机器学习(公式推导与代码实现)--sklearn机器学习库
Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
redis实现分布式锁的原理









