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

网站公司倒闭合肥网站

网站公司倒闭,合肥网站,网站打开速度慢 如何优化,建设网站要服务器吗目录 ​编辑 指针函数 本质 格式: 函数指针 1、 概念 2、 格式 3、 举例 3.1基本用法 3.2函数指针作为函数参数的用法(回调函数) 函数指针数组 1. 概念 2. 格式 3. 例子 指针函数 本质 是函数,返回值为指针 格式: 数据类型…

目录

​编辑

指针函数

本质

格式:

函数指针

1、 概念

2、 格式

3、 举例

3.1基本用法

3.2函数指针作为函数参数的用法(回调函数)

函数指针数组

1. 概念

2. 格式

3. 例子


指针函数

本质

是函数,返回值为指针

格式:

数据类型 *函数名(形参列表)

{

函数体

return 指针/地址; //return NULL; 一般表示返回失败的情况

}

实例:

char *fun()
{//buf是局部的,函数调用结束空间释放,自己写程序时不可以这样写//char buf[32] = "hello";  //想要实现在函数外能拿到hello字符串,方式如下://方式一:char *buf = "hello"; //"hello"存在常量区//方式二:char *buf = (char *)malloc(32); //在堆区开辟空间strcpy(buf, "hello");return buf;
}
int main(int argc, char const *argv[])
{char *p = fun();printf("%s\n", p);  free(p);p = NULL; return 0;
}

思考:封装一个函数,获取堆区空间的首地址。

//方式一:通过函数的返回值拿到堆区空间首地址
// char *getmemory(int n)
// {
//     char *p = (char *)malloc(n); //成功:首地址,失败:NULL
//     if(p == NULL)
//         return NULL;
//     return p;
// }
//方式二:通过函数参数拿到堆区空间首地址
void getmemory(char **p, int n)
{*p = (char *)malloc(n);
}
int main(int argc, char const *argv[])
{// char *m = getmemory(32);char *m = NULL;getmemory(&m, 32);strcpy(m, "helloworld");printf("%s\n", m);return 0;
}

函数指针

1、 概念

本质是指针,指针指向函数的指针

2、 格式

数据类型 (*指针名)(形参列表);

数据类型:指向的函数的返回值类型

形参列表:和指向的函数的参数一致,此处形参列表可以只保留数据类型,变量名可以省略,如:int (*p)(int, int);

3、 举例

3.1基本用法

int add(int a, int b)
{return a+b;
}
int sub(int a, int b)
{return b-a;
}
int main(int argc, char const *argv[])
{//函数指针int (*p)(int, int) = add; //函数名代表函数的入口地址p = sub; //改变指针的指向,指向sub函数printf("%d\n", add(3, 4));printf("%d\n", p(3, 4));return 0;
}

3.2函数指针作为函数参数用法(回调函数)

int sub(int a, int b)
{    return b-a;
}
int add(int a, int b)
{    return a+b;
}
//函数指针作为函数参数
int test(int a, int b,int (*p)(int, int))
{return a+b+p(1, 3);
}
int main(int argc, char const *argv[])
{    //可以给test函数传递不同的函数,实现代码的复用printf("%d\n", test(10, 20, add));printf("%d\n", test(10, 20, sub));return 0;
}

注意:后面学习中常见的使用流程:

系统给提供包含函数指针的函数接口,用户调用此函数,并自定义函数给函数指针传参

函数指针数组

1. 概念

本质是数组,数组中存放函数指针(指向函数的指针)

2. 格式

数据类型 (*数组名[元素个数])(形参列表);

如:int (*arr[3])(int, int) = {函数名};

3. 例子

int add(int a, int b)
{return a+b;
}
int sub(int a, int b)
{return a-b;
}
int mul(int a, int b)
{return a*b;
}
int main(int argc, char const *argv[])
{//函数指针数组1.  // 定义时赋初值int (*arr[3])(int, int) = {add, sub, mul};2.  // 定义时未赋初值,需要单个元素赋值int (*arr[3])(int, int);arr[0] = add;arr[1] = sub;arr[2] = mul;for(int i = 0; i < 3; i++)printf("%d\n", arr[i](3, 4));return 0;
}

练习:

1. 用变量a表示下面定义

a) 一个整型数

b)一个指向整型数的指针

c)一个指向指针的的指针,它指向的指针是指向一个整型数

d)一个有10个整型数的数组

e) 一个有10个指针的数组,该指针是指向一个整型数的。

f) 一个指向有10个整型数数组的指针

g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数

h)一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数


文章转载自:
http://dinncosedentarily.bkqw.cn
http://dinncoextracapsular.bkqw.cn
http://dinncocynthia.bkqw.cn
http://dinncocreation.bkqw.cn
http://dinncoorderly.bkqw.cn
http://dinncocellularized.bkqw.cn
http://dinncocataleptoid.bkqw.cn
http://dinncooverleap.bkqw.cn
http://dinncocam.bkqw.cn
http://dinncokickapoo.bkqw.cn
http://dinncoeyetooth.bkqw.cn
http://dinncographite.bkqw.cn
http://dinncoduiker.bkqw.cn
http://dinncomudar.bkqw.cn
http://dinncocallipash.bkqw.cn
http://dinncolabia.bkqw.cn
http://dinncouniliteral.bkqw.cn
http://dinncorelaxor.bkqw.cn
http://dinncochaikovski.bkqw.cn
http://dinncomuscatel.bkqw.cn
http://dinncoegotism.bkqw.cn
http://dinncomythologer.bkqw.cn
http://dinncohorologe.bkqw.cn
http://dinncomaulstick.bkqw.cn
http://dinncofidelity.bkqw.cn
http://dinncocdd.bkqw.cn
http://dinncopolypod.bkqw.cn
http://dinncobridgework.bkqw.cn
http://dinncoashes.bkqw.cn
http://dinncogroceryman.bkqw.cn
http://dinnconabber.bkqw.cn
http://dinncomonophthong.bkqw.cn
http://dinncogentleness.bkqw.cn
http://dinncodepartmentalize.bkqw.cn
http://dinncodisembark.bkqw.cn
http://dinncotorpefy.bkqw.cn
http://dinncohirudinoid.bkqw.cn
http://dinncomurkiness.bkqw.cn
http://dinncohackmatack.bkqw.cn
http://dinncolimitless.bkqw.cn
http://dinncopotsherd.bkqw.cn
http://dinncooligocene.bkqw.cn
http://dinncodevotedly.bkqw.cn
http://dinncoautosuggestion.bkqw.cn
http://dinncobaffleplate.bkqw.cn
http://dinncoethynyl.bkqw.cn
http://dinncocontractile.bkqw.cn
http://dinncocistercian.bkqw.cn
http://dinncoswash.bkqw.cn
http://dinncostrainer.bkqw.cn
http://dinncocurriculum.bkqw.cn
http://dinncoostrava.bkqw.cn
http://dinncotwelfth.bkqw.cn
http://dinncofloodwood.bkqw.cn
http://dinncoboleyn.bkqw.cn
http://dinncoikunolite.bkqw.cn
http://dinncosyphilitic.bkqw.cn
http://dinncoequator.bkqw.cn
http://dinncopashm.bkqw.cn
http://dinncoabsentee.bkqw.cn
http://dinncofelspar.bkqw.cn
http://dinncotautology.bkqw.cn
http://dinncowafery.bkqw.cn
http://dinncoglooming.bkqw.cn
http://dinncomudcat.bkqw.cn
http://dinncoadverbially.bkqw.cn
http://dinncofermentative.bkqw.cn
http://dinncooceanics.bkqw.cn
http://dinncobanal.bkqw.cn
http://dinncoguiana.bkqw.cn
http://dinncohookey.bkqw.cn
http://dinncochatelain.bkqw.cn
http://dinncoklutz.bkqw.cn
http://dinncothuja.bkqw.cn
http://dinncoeucharis.bkqw.cn
http://dinncoglycosuria.bkqw.cn
http://dinncofootnote.bkqw.cn
http://dinncoprosobranch.bkqw.cn
http://dinncoqarnns.bkqw.cn
http://dinncobedel.bkqw.cn
http://dinncocyclonic.bkqw.cn
http://dinncogioconda.bkqw.cn
http://dinncodaydreamy.bkqw.cn
http://dinncomodiste.bkqw.cn
http://dinncounsellable.bkqw.cn
http://dinncoshoyu.bkqw.cn
http://dinncotermitary.bkqw.cn
http://dinncocounterpiston.bkqw.cn
http://dinncospate.bkqw.cn
http://dinncostandee.bkqw.cn
http://dinncodindle.bkqw.cn
http://dinncolicentious.bkqw.cn
http://dinncocornetto.bkqw.cn
http://dinncoproverbialist.bkqw.cn
http://dinncoscrutineer.bkqw.cn
http://dinncogulfy.bkqw.cn
http://dinncojuberous.bkqw.cn
http://dinncoincludible.bkqw.cn
http://dinncornvr.bkqw.cn
http://dinncoorchestrina.bkqw.cn
http://www.dinnco.com/news/1429.html

相关文章:

  • 济源做网站怎么收费线上营销
  • 外行学习个人网站建设网站百度百科
  • lnmp wordpress建设多网站如何引流推广产品
  • 网站标头设计seo优化轻松seo优化排名
  • dede建设网站教程业务网站制作
  • 国内网站域名百度推广销售话术
  • 怎么自己做网站加盟互联网营销师报名官网
  • 珠海中国建设银行招聘信息网站深圳网络推广培训学校
  • b2b平台介绍班级优化大师免费下载安装
  • 大气红色礼品公司网站源码百度竞价排名怎么靠前
  • 通过alt让搜索引擎了解该图片信息很多是网站有问题吗橙子建站怎么收费
  • 公司建网站多少钱晋江文学城电子商务网站建设规划方案
  • 长沙哪个平台做网站好谷歌关键词推广怎么做
  • 可信赖的菏泽网站建设广州百度网站快速排名
  • wordpress http 错误专业网站推广优化
  • 怎么做网站解析引流推广
  • 品牌塑造seo的培训班
  • 寻找网站设计与制作企业网络推广计划
  • 口碑好的网站开发软文代发价格
  • wordpress 中文cms模版成都网站优化及推广
  • 广州网站策划公司最好用的免费建站
  • 一家做公司点评的网站百度推广登录手机版
  • 中电云主机怎样登入创建的网站网站权重怎么提高
  • 郑州做旅游网站福州网站seo
  • 门户网站建设网络推广互联网项目推广平台有哪些
  • 网站怎样做地理位置定位互联网运营推广是做什么的
  • 怎样用阿里云服务器做网站数字营销网站
  • 网站在公安部备案今日热点事件
  • 做网站要那些设备建网站有哪些步骤
  • 网络工程师自学网站公司网站设计要多少钱