当前位置:网站首页>函数指针数组
函数指针数组
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;
}
边栏推荐
猜你喜欢
随机推荐
oracle ASM磁盘空间的查看
【LeetCode】622.设计循环队列
Scala parallel collections, parallel concurrency, thread safety issues, ThreadLocal
【LeetCode】226.翻转二叉树
015-平衡二叉树(一)
013-二叉树
多媒体数据处理实验3:图像特征提取与检索
Path Prefixes (倍增!树上の二分)
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
English Grammar - Adverbial Clauses
索引(三)
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
Flink Yarn Per Job - Submit application
redis实现分布式锁的原理
Automated test browser driver download version
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
SQL Daily Practice (Nioke New Question Bank) - Day 5: Advanced Query
慢 SQL 分析与优化
Exception: Dataset not found. Solution
flush tables