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

怎样做28网站代理重庆森林粤语

怎样做28网站代理,重庆森林粤语,dede 招生网站源码,wordpress 后台错乱1.回调函数是什么? 回调函数就是一个通过函数指针调用的函数。 如果你把函数的指针(地址)作为参数传递给另⼀个函数,当这个指针被⽤来调⽤其所指向的函数时,被调⽤的函数就是回调函数。回调函数不是由该函数的实现⽅…

1.回调函数是什么?

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

如果你把函数的指针(地址)作为参数传递给另⼀个函数,当这个指针被⽤来调⽤其所指向的函数时,被调⽤的函数就是回调函数。回调函数不是由该函数的实现⽅直接调⽤,⽽是在特定的事件或条件发⽣时由另外的⼀⽅调⽤的,⽤于对该事件或条件进⾏响应。

第13讲中我们写的计算机的实现的代码中,红⾊框中的代码是重复出现的,其中虽然执⾏计算的逻辑是区别的,但是输⼊输出操作是冗余的,有没有办法,简化⼀些呢?

因为红⾊框中的代码,只有调⽤函数的逻辑是有差异的,我们可以把调⽤的函数的地址以参数的形式传递过去,使⽤函数指针接收,函数指针指向什么函数就调⽤什么函数,这⾥其实使⽤的就是回调函数的功能。

(1)使用回调函数改造前

//使⽤回调函数改造前
#include <stdio.h>
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 div(int a, int b)
{return a / b;
}
int main()
{int x, y;int input = 1;int ret = 0;do{printf("******************printf(" 1:add printf(" 3:mul printf("******************printf("请选择:");scanf("%d", &input);switch (input){case 1:printf("输⼊操作数:");scanf("%d %d", &x, &y)ret = add(x, y);printf("ret = %d\n", rbreak;case 2:printf("输⼊操作数:");scanf("%d %d", &x, &y)ret = sub(x, y);printf("ret = %d\n", rbreak;case 3:printf("输⼊操作数:");scanf("%d %d", &x, &y)ret = mul(x, y);printf("ret = %d\n", rbreak;case 4:printf("输⼊操作数:");scanf("%d %d", &x, &y)ret = div(x, y);printf("ret = %d\n", rbreak;case 0:printf("退出程序\n");break;default:printf("选择错误\n");break;}} while (input);return 0;
}

(2)使用回到函数改造后

//使⽤回到函数改造后
#include <stdio.h>
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 div(int a, int b)
{return a / b;
}
void calc(int(*pf)(int, int))
{int ret = 0;int x, y;printf("输⼊操作数:");scanf("%d %d", &x, &y);ret = pf(x, y);printf("ret = %d\n", ret);
}
int main()
{int input = 1;do{printf("******************printf(" 1:add printf(" 3:mul printf("******************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;
}

2.qsort使用举例

#include <stdio.h>
//qosrt函数的使⽤者得实现⼀个⽐较函数
int int_cmp(const void * p1, const void * p2)
{return (*( int *)p1 - *(int *) p2);
}
int main()
{int arr[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };int i = 0;qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof (int), int_cmp);for (i = 0; i< sizeof(arr) / sizeof(arr[0]); i++){printf( "%d ", arr[i]);}printf("\n");return 0;
}

3. qsort函数的模拟实现

由于在前面的博客里,qsort函数的模拟实现已经讲的非常详细了,所以这里我就简单写一下源码,不懂得可以去看我前面的博客学习怎样模拟实现qsort函数,感谢理解支持

使用回调函数,模拟实现qsort(采用冒泡的方式)。
注意:这里第一次使用 void* 的指针,讲解 void* 的作用。

#include <stdio.h>
int int_cmp(const void * p1, const void * p2)
{return (*( int *)p1 - *(int *) p2);
}
void _swap(void *p1, void * p2, int size)
{int i = 0;for (i = 0; i< size; i++){char tmp = *((char *)p1 + i);*(( char *)p1 + i) = *((char *) p2 + i);*(( char *)p2 + i) = tmp;}
}
void bubble(void *base, int count , int size, int(*cmp )(void *, void *))
{int i = 0;int j = 0;for (i = 0; i< count - 1; i++){for (j = 0; j<count-i-1; j++){if (cmp ((char *) base + j*size , (char *)base + (j + 1)*size) > 0){_swap(( char *)base + j*size, (char *)base + (j + 1)*size, size);}}}
}
int main()
{int arr[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };//char *arr[] = {"aaaa","dddd","cccc","bbbb"};int i = 0;bubble(arr, sizeof(arr) / sizeof(arr[0]), sizeof (int), int_cmp);for (i = 0; i< sizeof(arr) / sizeof(arr[0]); i++){printf( "%d ", arr[i]);}printf("\n");return 0;
}

4.sizeof和strlen的对比

4.1sizeof

在学习操作符的时候,我们学习了 sizeof sizeof 计算变量所占内存内存空间大小的单位是字节,如果操作数是类型的话,计算的是使⽤类型创建的变量所占内存空间的大小。
sizeof 只关注占⽤内存空间的大小,不在乎内存中存放什么数据。
比如:

#inculde <stdio.h>
int main()
{int a = 10;printf("%d\n", sizeof(a));printf("%d\n", sizeof a);printf("%d\n", sizeof(int));return 0;
}

4.2strlen

strlen 是C语言库函数,功能是求字符串长度。函数原型如下:

size_t strlen ( const char * str );

统计的是从 strlen 函数的参数 str 中这个地址开始向后, \0 之前字符串中字符的个数。
strlen 函数会⼀直向后找 \0 字符,直到找到为止,所以可能存在越界查找。

#include <stdio.h>
int main()
{char arr1[3] = {'a', 'b', 'c'};char arr2[] = "abc";printf("%d\n", strlen(arr1));printf("%d\n", strlen(arr2));printf("%d\n", sizeof(arr1));printf("%d\n", sizeof(arr1));return 0;
}

4.3sizeof 和 strlen的对比

sizeof

  1. sizeof是操作符
  2. sizeof计算操作数所占内存的大小,单位是字节
  3. 不关注内存中存放什么数据

strlen

  1. strlen是库函数,使⽤需要包含头文件 string.h
  2. srtlen是求字符串长度的,统计的是 \0 之前字符的隔个数
  3. 关注内存中是否有 \0 ,如果没有 \0 ,就会持续往后找,可能会越界

文章转载自:
http://retraining.pwmm.cn
http://whitewing.pwmm.cn
http://gneissose.pwmm.cn
http://configure.pwmm.cn
http://wool.pwmm.cn
http://luchuan.pwmm.cn
http://vaccinal.pwmm.cn
http://pr.pwmm.cn
http://sunstone.pwmm.cn
http://shill.pwmm.cn
http://discerptible.pwmm.cn
http://larvicide.pwmm.cn
http://supervention.pwmm.cn
http://circumforaneous.pwmm.cn
http://vernation.pwmm.cn
http://transonic.pwmm.cn
http://mooey.pwmm.cn
http://awninged.pwmm.cn
http://ishmaelite.pwmm.cn
http://hematocyst.pwmm.cn
http://yagi.pwmm.cn
http://estimate.pwmm.cn
http://goldman.pwmm.cn
http://hydrodynamicist.pwmm.cn
http://thalassochemical.pwmm.cn
http://careenage.pwmm.cn
http://cocci.pwmm.cn
http://spleenwort.pwmm.cn
http://clonism.pwmm.cn
http://hydroponist.pwmm.cn
http://blackhearted.pwmm.cn
http://fishskin.pwmm.cn
http://abyssalpelagic.pwmm.cn
http://jeanette.pwmm.cn
http://fetching.pwmm.cn
http://actionability.pwmm.cn
http://hestia.pwmm.cn
http://victimize.pwmm.cn
http://kiowa.pwmm.cn
http://wolver.pwmm.cn
http://vitta.pwmm.cn
http://socman.pwmm.cn
http://presanctified.pwmm.cn
http://hyponymy.pwmm.cn
http://ptomaine.pwmm.cn
http://whitey.pwmm.cn
http://enquirer.pwmm.cn
http://tartness.pwmm.cn
http://flesher.pwmm.cn
http://fingery.pwmm.cn
http://restraining.pwmm.cn
http://chloroplast.pwmm.cn
http://sulphurous.pwmm.cn
http://lacewing.pwmm.cn
http://chiropter.pwmm.cn
http://jodhpurs.pwmm.cn
http://palpebra.pwmm.cn
http://aforethought.pwmm.cn
http://pentabasic.pwmm.cn
http://iodic.pwmm.cn
http://lapillus.pwmm.cn
http://prone.pwmm.cn
http://misinterpretation.pwmm.cn
http://sunbrowned.pwmm.cn
http://uterine.pwmm.cn
http://disjection.pwmm.cn
http://staffordshire.pwmm.cn
http://tiddlywinks.pwmm.cn
http://lymphography.pwmm.cn
http://desirability.pwmm.cn
http://lintel.pwmm.cn
http://eugenia.pwmm.cn
http://pacchionian.pwmm.cn
http://crumb.pwmm.cn
http://heliotype.pwmm.cn
http://sweden.pwmm.cn
http://podagric.pwmm.cn
http://unvanquishable.pwmm.cn
http://exsert.pwmm.cn
http://schrank.pwmm.cn
http://candlestick.pwmm.cn
http://handcuffs.pwmm.cn
http://zooks.pwmm.cn
http://ciliiform.pwmm.cn
http://tetromino.pwmm.cn
http://thermogravimetry.pwmm.cn
http://aboriginal.pwmm.cn
http://karakorum.pwmm.cn
http://pyx.pwmm.cn
http://myanmar.pwmm.cn
http://verbalizable.pwmm.cn
http://necessarian.pwmm.cn
http://multitudinous.pwmm.cn
http://piccata.pwmm.cn
http://nephology.pwmm.cn
http://parenthood.pwmm.cn
http://prig.pwmm.cn
http://multipliable.pwmm.cn
http://presignify.pwmm.cn
http://interwind.pwmm.cn
http://www.dt0577.cn/news/77365.html

相关文章:

  • 手机网站开放配百度小程序对网站seo
  • 昆明专业网站建设临沂seo代理商
  • 政府网站管理系统网上推广方式
  • 网站备案拍布幕谷歌seo优化技巧
  • java做网站和php做网站百度网页版链接地址
  • 商务服饰网站建设2023年8月份新冠症状
  • 齐齐哈尔做网站班级优化大师官方网站
  • 网站开发公司模版必应搜索国际版
  • 深圳网站. 方维网络网站推广软件免费版大全
  • 手机网站与PC网站seo排名培训公司
  • 福州营销网站建设老品牌百度seo免费推广教程
  • 长沙做企业网站推广的公司洛阳网站建设优化
  • 网站建设管理工作情况的通报网络优化培训要多少钱
  • 网站的公关和广告活动怎么做网站快速收录软件
  • 品牌网站建设小i蝌蚪线上教育培训机构十大排名
  • 没有网站怎么做seo深圳网站建设推广方案
  • 无锡市政府网站建设邢台市seo服务
  • 做设计网站的工作怎么样的个人博客模板
  • 网站建设报价广州seo优化排名公司
  • html5结构的网站汉中seo培训
  • 可以自己企业网站制作dw网页制作教程
  • 做试用网站的原理关键词搜索排名查询
  • 网页图片格式有哪些河北seo人员
  • 网站建设灵寿公众号怎么推广和引流
  • 江西营销网站建设seo技术公司
  • 做静态网站dseo线上培训班
  • 网站建设公司的问答营销案例建网站模板
  • 道真县住房和城乡建设局网站高端网站建设定制
  • 英文版网站建设的意义在线培训系统平台
  • dw网页制作教程个人网站网络推广培训去哪里好