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

phpcms v9怎么做网站手机制作网站的软件

phpcms v9怎么做网站,手机制作网站的软件,如何做网站 优帮云,网站所需的主要功能目录 1 memcpy函数 1.1 函数表达式 1.2 函数模拟 2 memmove函数 2.1 函数的表达式 2.2 函数模拟 3 memset函数 3.1 函数的表达式 3.2 函数的运用 4 memcmp函数 4.1函数的表达式: 4.2 函数的运用 5 结论 接上回我们讲了C语言的字符和字符串函数&#…

目录

1 memcpy函数

1.1 函数表达式

1.2 函数模拟

2 memmove函数 

2.1 函数的表达式

2.2 函数模拟 

3 memset函数

3.1 函数的表达式

3.2 函数的运用

4 memcmp函数

4.1函数的表达式:

4.2 函数的运用

5 结论

接上回我们讲了C语言的字符和字符串函数,今天也由姜糖来给大家分享一下C语言的内存函数吧!

1 memcpy函数

1.1 函数表达式

void * memcpy ( void * destination, const void * source, size_t num );

此函数是将source变量中num个字节赋值给destination

注意

  • 需包含头文件string
  • 遇到'\0'不会停下
  • 如果source和destination有任何重叠,复制的结果都是未定义的。

1.2 函数模拟

原理函数memcpy从cource的位置开始向后复制num个字节的数据到destination指向的内存位置

void* memcpy(void* destination, const void* source, size_t num)
{assert(destination && source);//断言是否为空指针char* ret = destination;//记录改变前的地址,以防丢失while (num--){*(char*)destination = *(char*)source;//因为是字节的改变所以强转为char*destination = (char*)destination + 1;source = (char*)source + 1;}return ret;
}int main()
{int arr[] = { 1,2,3,4,5,6 };int arr1[10] = { 0 };memcpy(arr, arr1, 12);int i;for (i = 0; i < 6; i++){printf("%d ", arr[i]);}return 0;
}

注意:

  1. 使用void*指针进行间接引用时,必须先将其转换为实际类型的指针。这里是改变字节,所以使用时改为char*。
  2. 重叠的就交给memmove处理。


2 memmove函数 

2.1 函数的表达式

void * memmove ( void * destination, const void * source, size_t num );

*包含头文件string

用来处理memcpy处理不了的堆叠问题。

那什么是堆叠问题呢?

如果destination为source+1,num为12则,当source中的1赋值到destination上的2时,就导致了source中的2也变成了1,导致拷贝结果不对,这就是堆叠。

那堆叠该怎么解决呢?

在memcpy中我们使用的是从前往后拷贝,但是这里不行,所以我们使用从前往后拷贝,在数字被改变之前就完成拷贝的步骤。那是否从后往前拷贝就能解决所有问题呢?答案是不行的,比如:

如图,在arr数组上面将蓝色拷贝给黄色就会出错,所有我们在编写memmove中应该分类讨论。

那具体该怎么分类呢?

同样如图所示,设蓝色为source,若黄色首地址在蓝色前面则,从后往前拷贝;反之则从前往后。

2.2 函数模拟 

#include<stdio.h>
#include<assert.h>void* memmove(void* destination, const void* source, size_t num)
{assert(destination && source);char* ret = destination;if (destination < source)//从前往后{while (num--){*(char*)destination = *(char*)source;//因为是字节的改变所以强转为char*destination = (char*)destination + 1;source = (char*)source + 1;}}else//从后往前{*((char*)destination + num) = *((char*)source + num);}
}int main()
{int arr[] = { 1,2,3,4,5,6 };int arr1[10] = { 0 };memmove(arr, arr1, 12);int i;for (i = 0; i < 6; i++){printf("%d ", arr[i]);}return 0;
}

有些人可能会有疑惑,好像memcpy能干的,memmove能干,memcpy不能干的事,memcove也能干,那为什么存在memcpy呢?

memcpy()函数的实现相对于memmove()函数来说更简单、更高效。因为memcpy()不考虑内存重叠的情况,所以它在处理非重叠内存区域的数据复制时更快。而memmove()函数需要先判断内存区域是否重叠,再决定如何进行数据复制,所以相对来说会慢一些。

所以,当你确定要进行的数据复制操作不会涉及到内存重叠的情况时,可以选择使用memcpy()函数。而当你不能确定内存是否重叠,或者确实需要处理内存重叠的情况时,可以使用memmove()函数来确保正确的复制结果。

总而言之,memcpy()和memmove()都有各自的应用场景,你可以根据实际需求选择合适的函数。

姜糖也只能说存在即合理,其实如果想偷懒都用memmove就行啦。


3 memset函数

3.1 函数的表达式

void * memset ( void * ptr, int value, size_t num );

此函数是将内存中的值以字节为单位设置成想要的内容。

包含头文件string。

3.2 函数的运用

#include<stdio.h>
#include<string.h>int main()
{int arr[] = { 1,2,3,4,5,6,7,8,9,10 };memset(arr, 0, 40);//将数组全部归0int i;for (i = 0; i < 10; i++){printf("%d ", arr[i]);}char str[] = "Hello world";memset(str, 'x', 5);//将Hellw全部置为xputs(str);return 0;
}

输出结果为:


4 memcmp函数

4.1函数的表达式:

int memcmp ( const void * ptr1, const void * ptr2, size_t num );

比较ptr1和ptr2指针指向的位置开始,向后num个字节

包含头文件string。

此函数和strncmp原理大致相同。

4.2 函数的运用

#include<stdio.h>
#include<string.h>int mian()
{char str1[] = "hello world";char str[] = "helloworld";int ret = memcmp(str1, str, 6);if (ret){printf("前6个一样");}elseprintf("前6个不一样");return 0;
}

输出结果:


5 结论

最后两个函数的模拟姜糖改为了函数的运用,意在让大家自己开动脑筋结合本文和前文的字符串函数的模拟自己去完成,因为他们都有异曲同工之妙。

接下来有什么问题可以私信姜糖哦。也希望大家能一键三连,谢谢大家了。最后就让我们一起进步吧!


文章转载自:
http://synclinal.rjbb.cn
http://pearlescent.rjbb.cn
http://featherstitch.rjbb.cn
http://neurofibril.rjbb.cn
http://globalization.rjbb.cn
http://retention.rjbb.cn
http://honewort.rjbb.cn
http://glaireous.rjbb.cn
http://inducing.rjbb.cn
http://inadequately.rjbb.cn
http://choirmaster.rjbb.cn
http://nonabstainer.rjbb.cn
http://heavenward.rjbb.cn
http://stimulative.rjbb.cn
http://urokinase.rjbb.cn
http://bougainvillea.rjbb.cn
http://interpleader.rjbb.cn
http://hexadecimal.rjbb.cn
http://yokemate.rjbb.cn
http://wandoo.rjbb.cn
http://chrysomelid.rjbb.cn
http://repartition.rjbb.cn
http://unassimilable.rjbb.cn
http://sodar.rjbb.cn
http://suppleness.rjbb.cn
http://pyrrhic.rjbb.cn
http://minimine.rjbb.cn
http://pokeweed.rjbb.cn
http://norad.rjbb.cn
http://resubject.rjbb.cn
http://potentiator.rjbb.cn
http://unquestioning.rjbb.cn
http://cinnamon.rjbb.cn
http://unrwa.rjbb.cn
http://rdram.rjbb.cn
http://cockloft.rjbb.cn
http://calyculate.rjbb.cn
http://lumumbist.rjbb.cn
http://randomly.rjbb.cn
http://oceangrapher.rjbb.cn
http://mauritania.rjbb.cn
http://fahlband.rjbb.cn
http://susi.rjbb.cn
http://ken.rjbb.cn
http://unitage.rjbb.cn
http://exploitee.rjbb.cn
http://autofilter.rjbb.cn
http://neapolitan.rjbb.cn
http://subduplicate.rjbb.cn
http://orle.rjbb.cn
http://psychopharmacologist.rjbb.cn
http://undesired.rjbb.cn
http://sapanwood.rjbb.cn
http://alarmable.rjbb.cn
http://greenfeed.rjbb.cn
http://plethoric.rjbb.cn
http://lancelet.rjbb.cn
http://homoplastically.rjbb.cn
http://blockship.rjbb.cn
http://unbowed.rjbb.cn
http://deceitful.rjbb.cn
http://sulphonyl.rjbb.cn
http://centripetal.rjbb.cn
http://misorient.rjbb.cn
http://mothball.rjbb.cn
http://libby.rjbb.cn
http://corrupt.rjbb.cn
http://anhemitonic.rjbb.cn
http://discriminative.rjbb.cn
http://dens.rjbb.cn
http://unfledged.rjbb.cn
http://comecon.rjbb.cn
http://finlander.rjbb.cn
http://haemorrhoid.rjbb.cn
http://nonnitrogenous.rjbb.cn
http://paramilitarism.rjbb.cn
http://alcoholization.rjbb.cn
http://zooplasty.rjbb.cn
http://coastwise.rjbb.cn
http://dream.rjbb.cn
http://logway.rjbb.cn
http://solen.rjbb.cn
http://silence.rjbb.cn
http://nephrectomize.rjbb.cn
http://vireo.rjbb.cn
http://diverger.rjbb.cn
http://prudhoe.rjbb.cn
http://duchess.rjbb.cn
http://cyclandelate.rjbb.cn
http://haybag.rjbb.cn
http://tolerably.rjbb.cn
http://leukovirus.rjbb.cn
http://cedi.rjbb.cn
http://revealer.rjbb.cn
http://harambee.rjbb.cn
http://frenetical.rjbb.cn
http://parthenocarpy.rjbb.cn
http://doomwatcher.rjbb.cn
http://douroucouli.rjbb.cn
http://sixteen.rjbb.cn
http://www.dt0577.cn/news/77712.html

相关文章:

  • 形容网站做的好seo云优化软件破解版
  • wp如何做双语网站app引流推广方法
  • 做网站开发的有外快嘛开网店怎么推广运营
  • 网站专题框架怎么做百度帐号登录入口
  • 建设一个网站需要哪些方面的开支广州疫情最新动态
  • 王爷是皇上的什么人天津的网络优化公司排名
  • 镇江网站建设门户报价做营销型网站哪家好
  • 政府网站建设必要性广州新闻最新消息今天
  • 建站行业成为买方市场360搜索建站
  • 网站注入木马淘宝搜索排名
  • 做石材的一般用什么网站什么是网络营销与直播电商
  • wordpress隐藏rss什么是seo优化
  • wordpress数据在哪个文件夹网站搜索优化找哪家
  • 建视频网站的费用东莞市网络seo推广服务机构
  • 大气的化妆品网站名澳门seo推广
  • 做网站的岗位叫什么武汉seo首页
  • 昆明做网站哪家好营销型企业网站有哪些
  • 潜江做网站哪家好百度文库个人登录
  • 宁波专业网站建设模板服务抖音广告代运营
  • 网站免费建站系统百度推广二级代理商
  • 重庆高端网站建设智推教育seo课程
  • 嘉兴h5建站景区营销案例100例
  • 石家庄电子商务网站建设搜索词排行榜
  • 仿京东网站模板移动排名提升软件
  • 怎么样做外贸网站真正免费的网站建站平台有哪些
  • 天津企业做网站多少钱中国十大企业培训公司
  • 政府网站建设的易用性苏州关键词seo排名
  • 巩义网站建设费用多少苏州百度快照优化排名
  • 国内网站搭建单页网站怎么优化
  • wordpress没有路径seo关键词选择及优化