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

沈阳世纪兴网站制作企业网站建设方案模板

沈阳世纪兴网站制作,企业网站建设方案模板,easyUI网站开发,电商平台谈双11变冷一. 函数指针变量 1. 函数指针变量的定义: 类比数组指针变量,数组指针变量是存放数组地址的变量,那么同理,函数指针变量就是存放函数地址的变量。 2. 创建函数指针变量: 函数是有地址的&#xff0…

一.   函数指针变量

1.   函数指针变量的定义:

类比数组指针变量,数组指针变量是存放数组地址的变量,那么同理,函数指针变量就是存放函数地址的变量。


2.   创建函数指针变量:

函数是有地址的,函数名就是函数的地址。此外,&函数名也是函数的地址,二者本质上一样,因此,它们的地址也一样。

bebbf71b42574f8993a56d032eaa9707.png

我们如果想将函数的地址存放起来,就需要创建函数指针变量了,以下是函数指针变量的创建方式(以上图函数为例):

int (* p)(int x,int y)=plus; 

对函数指针变量创建的理解,和对数组指针变量的理解是相似的:

P是一个变量,那么(*p)意思是这个变量是个指针变量;在括号中的(int x,int y)表示p这个指针变量指向的参数的类型和参数的个数。要注意的是,在这里写下x,y和不写都是可以的,只要表明参数的个数和类型就行;最后,最前面的int表示这个函数指针变量指向的返回类型是int类型的。


3.   函数指针变量的使用:

我们通过创建一个加法函数来学习函数指针变量的使用:

int plus(int x, int y)

return x + y;

}

int main()

{

     int x = 0; int y = 0;

     printf("请输入两个数");

     scanf("%d %d", &x, &y);

     int (*p)(int x, int y) = plus;//创建一个函数指针变量来存放plus这个函数

     printf("%d", (*p)(x, y));

     return 0;

}

对于(*p)(x, y)这行代码,我们可以这么理解:

通过函数指针p调用指向的函数,并将x和y作为参数传给该函数。



二.   typedef关键字

在C语言中,很多时候有很多类型比较长,这时候,如果我们想将这些类型简化,就需要使用typedef关键字,以下是它的基本使用方法(以
unsigned int 为例)

typedef unsigned int uint;

这样,在之后敲写代码的时候,就可以用uint 来代替了。

注:对于数组指针和函数指针要命名时,方法稍有不同:

数组指针:eg:  typedef int(* name)[8]

函数指针:eg:  typedef int(* name)(int x,int y)



三.   函数指针数组

按照之前所说的理解方式,我们重点关注最后两个字:数组;所以,函数指针数组是存放函数指针变量的数组,下面,我们通过创建一个简单的计算器来学习函数指针数组的应用。


创建简单计算器的基本步骤:

(1)创建四个函数,分别可以进行加减乘除的运算

(2)创建一个菜单,表示计算器的开始界面

(3)让读者选择是否开始使用计算器

(4)让读者选择要使用的计算方法

(5)让读者输入要计算的数

(6)计算结果并给出答案


函数指针数组的创建和使用和函数指针变量类似,以下是其创建和使用格式:

创建:int (*p[5])(int x, int y)

由于[ ]的计算等级比*高,所以p先和[ ]结合,意味着p是一个数组;其再和*结合,意味着这是一个指针数组,而这个指针数组中存放的就是一个或多个函数的地址。这样也就意味着,所有存放的函数的参数和返回值必须是一样的,这样函数指针数组才可以使用。

使用:(*p[input])(x, y)

*p[input]的意思是指向这个函数指针数组中选择的input中的函数,用(x,y)将其赋值,并使用这个函数。


以下是参考代码:

int first(int x, int y)
{
    return x + y;
}
int second(int x,int y)
{
    return x - y;
}
int third(int x, int y)
{
    return x * y;
}
int forth(int x, int y)
{
    return x / y;
}
void menu(void)
{
    printf("******************************\n");
    printf("**********0.退出  ************\n");
    printf("**********1.加法  ************\n");
    printf("**********2.减法  ************\n");
    printf("**********3.乘法  ************\n");
    printf("**********4.除法  ************\n");
    printf("******************************\n");
}
int main()
{
    int input = 0;//选择数
    int x = 0;
    int y = 0;//要计算的数
    //创建一个函数指针数组来存放函数指针变量
    int (*p[5])(int x, int y) = { 0,&first,&second,&third,&forth };
    int a = 0;//创建一个数来接收函数传过来的变量,便于理解和打印
    do
    {
        menu();
        printf("请选择:");
        scanf("%d", &input);
        if (input <= 4 && input >= 1)
        {
            printf("请输入要计算的数\n");
            scanf("%d %d", &x, &y);
            a = (*p[input])(x, y);
            printf("计算结果是%d\n", a);
        }
        else if (input == 0)
        {
            printf("退出计算器\n");
        }
        else
        {
            printf("选择错误,请重新选择\n");
        }
    } while (input);
    return 0;



四.    几个基本概念的辨别
数组指针:是指针,里面存的是数组的地址
指针数组:是数组,里面存的是一个或多个指针(地址)
函数指针:是指针,里面存的是一个函数的地址
函数指针数组:是数组,里面存的是一个或多个函数的地址



数组指针:

创建:int (*p)[5]=&arr
使用:(*p)[想找的数组的下标数]



指针数组:

创建:int *arr[3]={arr1,arr2,arr3}
使用:arr[arr中数组的下标][arr 1/2/3中数组的下标]



函数指针:

创建:int (*p)(int x,int y)=&函数名;
使用:(*p)(x,y)



函数指针数组:
创建:int(*p[5])(int x,int y)={&函数名1,&函数名2}
使用:(*p[想找的函数名的下标])(x,y)



 

 


文章转载自:
http://dravidic.bbrf.cn
http://ladleful.bbrf.cn
http://poise.bbrf.cn
http://zinkenite.bbrf.cn
http://factualist.bbrf.cn
http://retrievable.bbrf.cn
http://assimilable.bbrf.cn
http://clarify.bbrf.cn
http://echeveria.bbrf.cn
http://streetward.bbrf.cn
http://compensatory.bbrf.cn
http://sludgeworm.bbrf.cn
http://blastopore.bbrf.cn
http://interfluent.bbrf.cn
http://exergonic.bbrf.cn
http://atlantean.bbrf.cn
http://athanasy.bbrf.cn
http://geostatic.bbrf.cn
http://whaleback.bbrf.cn
http://diamorphine.bbrf.cn
http://phaenogam.bbrf.cn
http://retroverted.bbrf.cn
http://fisheater.bbrf.cn
http://friar.bbrf.cn
http://polyglottous.bbrf.cn
http://electropolar.bbrf.cn
http://metalogue.bbrf.cn
http://connivance.bbrf.cn
http://dominion.bbrf.cn
http://heliography.bbrf.cn
http://unfamous.bbrf.cn
http://hatchway.bbrf.cn
http://vermiculated.bbrf.cn
http://dabber.bbrf.cn
http://overdrawn.bbrf.cn
http://shakiness.bbrf.cn
http://nrem.bbrf.cn
http://wincey.bbrf.cn
http://georgina.bbrf.cn
http://benni.bbrf.cn
http://elohist.bbrf.cn
http://vamper.bbrf.cn
http://sleight.bbrf.cn
http://subtilin.bbrf.cn
http://informality.bbrf.cn
http://cabalist.bbrf.cn
http://cst.bbrf.cn
http://kittenish.bbrf.cn
http://servility.bbrf.cn
http://calumniate.bbrf.cn
http://hurriedly.bbrf.cn
http://coachwork.bbrf.cn
http://glimmering.bbrf.cn
http://membra.bbrf.cn
http://anglophone.bbrf.cn
http://seastrand.bbrf.cn
http://woven.bbrf.cn
http://saltbush.bbrf.cn
http://highjack.bbrf.cn
http://heterokaryotic.bbrf.cn
http://knead.bbrf.cn
http://westerveldite.bbrf.cn
http://philhellene.bbrf.cn
http://intercurrent.bbrf.cn
http://unforgotten.bbrf.cn
http://cooperativity.bbrf.cn
http://notability.bbrf.cn
http://anticyclonic.bbrf.cn
http://koorajong.bbrf.cn
http://sainthood.bbrf.cn
http://generalissimo.bbrf.cn
http://accompanier.bbrf.cn
http://hypervisor.bbrf.cn
http://trist.bbrf.cn
http://hosel.bbrf.cn
http://thickset.bbrf.cn
http://calciferous.bbrf.cn
http://landrover.bbrf.cn
http://unsalted.bbrf.cn
http://dextrine.bbrf.cn
http://christless.bbrf.cn
http://coquettish.bbrf.cn
http://acetazolamide.bbrf.cn
http://tyrol.bbrf.cn
http://thrombi.bbrf.cn
http://scuffle.bbrf.cn
http://khedive.bbrf.cn
http://poundal.bbrf.cn
http://clove.bbrf.cn
http://xerothermic.bbrf.cn
http://woad.bbrf.cn
http://abolishment.bbrf.cn
http://sensual.bbrf.cn
http://pulsatory.bbrf.cn
http://northeast.bbrf.cn
http://hornet.bbrf.cn
http://slickness.bbrf.cn
http://antiproton.bbrf.cn
http://manageable.bbrf.cn
http://dinkel.bbrf.cn
http://www.15wanjia.com/news/104040.html

相关文章:

  • 非国产手机浏览器关键词自动优化
  • 免费网站制作多少钱seo教程免费
  • 南昌个人网站制作怎么做网站页面优化方案
  • 网站如何做h5动态页面设计seo建设招商
  • 口碑做团购网站北京seo优化分析
  • 甘肃省党风建设作风评议网站淘宝seo具体优化方法
  • 网络舆情网站seo是指什么职位
  • 网站建设与制作视频教学武汉关键词seo排名
  • wordpress 评论 邮件seo推广技巧
  • 资兴市网站建设哪个好推广公司有哪些公司
  • 怎么搜索整个网站网站建设苏州
  • 在北京网站建设的岗位职责百度app平台
  • 新余网站开发公司广州专做优化的科技公司
  • 科技网站配色方案四川企业seo推广
  • 上海微信网站小红书推广引流软件
  • 做网站的优势windows优化大师好不好
  • 电子商务网站建设第三章答案广州seo运营
  • 做网站前需要做什么准备东莞seo计费管理
  • 太原做网站的通讯公司百度百家号
  • 政府单位如何做网站seo服务的内容
  • 网站做内嵌自媒体十大平台
  • 天津响应式网站建设最佳磁力吧ciliba搜索引擎
  • 小型的做网站公司从哪里接的项目网络营销产品推广方案
  • 举报不良网站信息怎么做长沙网站seo外包
  • 旅游品牌网站的建设做网站优化的公司
  • 做网站公司能赚钱吗重庆seo网站哪家好
  • 做网站实现自动生成pdf域名查询ip138
  • 福州公司建站模板上海抖音seo公司
  • 微信24小时人工客服网站搜索引擎优化的方法
  • 怎么做网站赚钱软件中国营销网