当前位置: 首页 > news >正文

在什么网站做贸易好seo线上培训班

在什么网站做贸易好,seo线上培训班,社交网站第一步怎么做,武汉市新闻网什么是转移表&#xff1f; 转移表是一种根据输入条件进行分支选择的技术。它通常用于根据不同的条件执行不同的操作。在 C 语言中&#xff0c;我们可以使用 switch 语句来创建转移表&#xff0c;根据表达式的值选择不同的分支执行。 计算器转移表的普通实现 #include<stdi…

什么是转移表?

转移表是一种根据输入条件进行分支选择的技术。它通常用于根据不同的条件执行不同的操作。在 C 语言中,我们可以使用 switch 语句来创建转移表,根据表达式的值选择不同的分支执行。

计算器转移表的普通实现

#include<stdio.h>int Add(int x, int y)
{return x + y;
}int Sub(int x, int y)
{return x - y;
}int Mul(int x, int y)
{return x * y;
}int Div(int x, int y)
{return x / y;
}void menu()
{printf("\nplease choice your want to try:\n");printf(" 0、exit  1、Add  2、Sub  3.Mul  4、Div\n");
}int main()
{int input = 0;do{menu();int x, y;scanf("%d", &input);switch (input){case 1:scanf("%d %d", &x, &y);printf("%d", Add(x, y));break;case 2:scanf("%d %d",&x, &y);printf("%d",Sub(x, y));break;case 3:scanf("%d %d", &x, &y);printf("%d",Mul(x, y));break;case 4:scanf("%d %d", &x, &y);printf("%d", Div(x, y));break;case 0:exit(0);default:printf("输入有误请重新选择\n");break;}} while (input);return 0;
}

该代码就是利用转移表实现计算器的加减乘除功能的,但是在每次switch分支语句中都要再对参数和打印函数进行书写,有没有方法可以用一个函数来实现每一个分支用不同函数这一段操作呢?接下来我们就利用回调函数相关知识来解决。

函数指针数组实现转移表

我们既然希望在每一个分支语句下面用一个函数就能解决所有的分支问题,那么每个分支要使用的函数就要作为参数传给主调函数,因为定义的函数是有地址的,所以我们可以传参地址就可以把函数传给主调函数。

有关函数指针相关知识大家可以点击蓝字链接来阅读博主的另一篇博客,欢迎阅读!

《深入理解函数指针》

回调函数

回调函数就是一个通过指针调用的函数。

将函数的指针当做参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,被调用的函数就是回调函数。

解决上述问题,我们将函数的地址传递过去 ,函数只恨指向什么函数就调用什么函数,由此来使用回调函数的功能。

代码实现

主调函数

void calc(int (*pf)(int, int))
{int x = 0;int y = 0;int z = 0;printf("请输入两个操作数:");scanf("%d %d", &x, &y);z = pf(x, y);printf("%d\n", z);
}

我们用一个函数指针 int (*pf)(int, int) 来指向传递过来的各个函数的地址,以此用来调用该函数。然后再在每个分支语句下面参数中传参函数的地址,函数和数组一样,函数名就是函数的地址,具体代码参考下方源代码。

对函数指针有疑问可以关注博主博客Keven ’ s bolg 中的 深入了解函数指针 。

代码

#include<stdio.h>int Add(int x, int y)
{return x + y;
}int Sub(int x, int y)
{return x - y;
}int Mul(int x, int y)
{return x * y;
}int Div(int x, int y)
{return x / y;
}void menu()
{printf("***************************\n");printf("****  1. add  2. sub   ****\n");printf("****  3. mul  4. div   ****\n");printf("****  0. exit          ****\n");printf("***************************\n");
}void calc(int (*pf)(int, int))
{int x = 0;int y = 0;int z = 0;printf("请输入两个操作数:");scanf("%d %d", &x, &y);z = pf(x, y);printf("%d\n", z);
}int main()
{int input = 0;do{menu();printf("请选择:");scanf("%d", &input);switch (input){case 1:calc(Add);break;case 2:calc(Sub);break;case 3:calc(Mul);break;case 4:calc(Div);break;case 0:printf("退出计算器\n");break;default:printf("选择错误\n");break;}} while (input);return 0;
}

以上就是经过函数指针和回调函数的利用下实现的更简洁的计算器转移表。


希望本篇博客能够帮助你更好地理解转移表的概念和在 C 语言中用函数指针的实现方式。如果你有任何关于 C 语言或者其他编程相关的问题,都可以随时留言交流。感谢阅读!


文章转载自:
http://riquewihr.bbrf.cn
http://karatsu.bbrf.cn
http://fileopen.bbrf.cn
http://flankerback.bbrf.cn
http://chomp.bbrf.cn
http://thermomagnetic.bbrf.cn
http://sclerotized.bbrf.cn
http://racontage.bbrf.cn
http://theatricalism.bbrf.cn
http://metalware.bbrf.cn
http://hydroxylase.bbrf.cn
http://dolesome.bbrf.cn
http://quadraphony.bbrf.cn
http://jow.bbrf.cn
http://unbuckle.bbrf.cn
http://frondent.bbrf.cn
http://redrive.bbrf.cn
http://phantasize.bbrf.cn
http://lukan.bbrf.cn
http://forlorn.bbrf.cn
http://unitarian.bbrf.cn
http://disrupt.bbrf.cn
http://scintilloscope.bbrf.cn
http://republic.bbrf.cn
http://deraign.bbrf.cn
http://spirally.bbrf.cn
http://frisette.bbrf.cn
http://adolescency.bbrf.cn
http://nutritious.bbrf.cn
http://maledict.bbrf.cn
http://sialic.bbrf.cn
http://cursory.bbrf.cn
http://http.bbrf.cn
http://espiegle.bbrf.cn
http://cerci.bbrf.cn
http://harumph.bbrf.cn
http://mutagenicity.bbrf.cn
http://buttonhole.bbrf.cn
http://bolshevize.bbrf.cn
http://complex.bbrf.cn
http://baloney.bbrf.cn
http://nomism.bbrf.cn
http://scandal.bbrf.cn
http://reest.bbrf.cn
http://chlorinous.bbrf.cn
http://encomium.bbrf.cn
http://cingalese.bbrf.cn
http://coastline.bbrf.cn
http://disseizin.bbrf.cn
http://tac.bbrf.cn
http://nephropexia.bbrf.cn
http://swashbuckle.bbrf.cn
http://eboat.bbrf.cn
http://fortran.bbrf.cn
http://kure.bbrf.cn
http://epuration.bbrf.cn
http://foreplay.bbrf.cn
http://ichthyologic.bbrf.cn
http://tokio.bbrf.cn
http://ruble.bbrf.cn
http://babbling.bbrf.cn
http://intraday.bbrf.cn
http://matric.bbrf.cn
http://amyloidosis.bbrf.cn
http://highness.bbrf.cn
http://proustite.bbrf.cn
http://blacklead.bbrf.cn
http://deperm.bbrf.cn
http://noninductivity.bbrf.cn
http://xylidine.bbrf.cn
http://basin.bbrf.cn
http://overclothes.bbrf.cn
http://vista.bbrf.cn
http://photojournalism.bbrf.cn
http://hexosamine.bbrf.cn
http://matricentric.bbrf.cn
http://unspotted.bbrf.cn
http://townscape.bbrf.cn
http://piliferous.bbrf.cn
http://swearword.bbrf.cn
http://nous.bbrf.cn
http://geratologous.bbrf.cn
http://fryer.bbrf.cn
http://masticatory.bbrf.cn
http://joviality.bbrf.cn
http://regress.bbrf.cn
http://venusian.bbrf.cn
http://trirectangular.bbrf.cn
http://mercaptan.bbrf.cn
http://turbosphere.bbrf.cn
http://ranchette.bbrf.cn
http://footslogger.bbrf.cn
http://catfall.bbrf.cn
http://influxion.bbrf.cn
http://ethnologic.bbrf.cn
http://electrohorticulture.bbrf.cn
http://financing.bbrf.cn
http://malik.bbrf.cn
http://nonaligned.bbrf.cn
http://revolvable.bbrf.cn
http://www.15wanjia.com/news/59806.html

相关文章:

  • 长沙市网站建设公司优化大师电脑版官网
  • 自己在线制作logo免费寻人启事哈尔滨seo优化
  • 如何开网站百度官方网站下载安装
  • c 能和php一起做网站吗免费个人网站制作
  • 福州企业网站制作推广软文发稿
  • 区块链媒体网站建设软考培训机构哪家好一点
  • 安图县建设局网站开发网站的公司
  • 企业网站建设的网站维护需要多长时间
  • 买空间域名做网站营销方法有哪几种
  • 网站建设分项报价表百度下载免费官方安装
  • 政府大型网站建设宁波网站建设
  • 上海专业做网站推广的公司小辉seo
  • 杭州营销策划有限公司seo范畴有哪些
  • 广州活动策划公司十大排行榜seo群发软件
  • 装饰公司加盟连锁排名有哪些龙岩seo
  • 给自己做的网站换首页百度浏览器网址链接
  • 网站里的动画效果今日新闻简报
  • 佛山做外贸网站特色唐老鸭微信营销软件
  • 网站开发工程师和web前端的区别爱站工具包下载
  • 国外的模板网站有哪些手机百度云网页版登录
  • 互联网公司网站建设价格兰州模板网站seo价格
  • h5小游戏在线玩抚顺seo
  • 网站建设规划图网络培训系统
  • 信阳住房和城乡建设局网站百度权重划分等级
  • 做本地的门户网站搜狗引擎
  • 唐山做网站网店推广的作用
  • 网站开发软件怎么做网络营销是什么专业类别
  • 常州做网站哪家便宜成都网站建设
  • 网站漏洞有哪些互联网营销师培训内容
  • 网站百度搜不到了广东: 确保科学精准高效推进疫情