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

31 - memmove()函数

文章目录

  • 1 函数原型
  • 2 参数
  • 3 返回值
  • 4 示例

1 函数原型

memmove():移动内存块,函数原型如下:

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

cstring库描述如下:

Move block of memory
1. Copies the values of num bytes from the location pointed by source to the memory block pointed by destination.
2. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.
3. The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data.
4. The function does not check for any terminating null character in source - it always copies exactly num bytes.
5. To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least num bytes.
  1. memmove()函数:
    (1)从source指向的内存块直接复制num个字节的值到destination指向的内存块;
    (2)和memcpy()函数的功能基本相同,区别在于memmove()函数能够正确处理内存重叠的情况。

2 参数

memmove()函数有三个参数source、destination和num:

  1. source是指向源内存块的指针,类型为void*;
  2. destination是指向目标内存块的指针,类型为void*;
  3. num是要复制的字符数,类型为size_t。

cstring库描述如下:

destination
1. Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.source
1. Pointer to the source of data to be copied, type-casted to a pointer of type const void*.num
1. Number of bytes to copy.
2. size_t is an unsigned integral type.

3 返回值

memmove()函数的返回值类型为void*型:

  1. 返回指向目标内存块的指针destination。
    cstring库描述如下:
1. destination is returned.

4 示例

示例代码如下所示:

int main() {//char str[] = "abcdefghijklmn";//printf("移动前:%s\n", str);//memmove(str + 6, str + 4, 6);//printf("移动后:%s\n", str);//return 0;
}

代码运行结果如下图所示:

在这里插入图片描述
代码及运行结果分析如下:

  1. 期望用"efghij"替换"ghijkl",替换成功。
http://www.lryc.cn/news/420162.html

相关文章:

  • 【深度学习】创建和训练Transformer神经网络模型,将葡萄牙语翻译成英语
  • [Qt][多元素控件]详细讲解
  • /var/log/里面的文件具体是什么?linux的登录文件
  • JVM知识总结(双亲委派机制)
  • YOLOv2:更快更准的目标检测
  • 硬件工程师笔面试真题汇总
  • 【vue+marked】marked
  • 无人机之热成像篇
  • 浅谈C/C++指针和引用在Linux和Windows不同环境下的编码风格
  • 【C#】一个项目移动了位置,或者换到其他电脑上,编译报错 Files 的值“IGEF,解决方法
  • 代码随想录算法训练营第五十八天|拓扑排序精讲 、dijkstra(朴素版)精讲
  • 【ARM】ULINK Pro如何和SWD接口进行连接调试
  • react框架安全设计
  • Kafka生产调优实践。Kafka消息安全性、消息丢失、消息积压、保证消息顺序性
  • DDColor部署安装,在服务器Ubuntu22.04系统——点动科技
  • 使用 SSL/TLS 加密保障 RocketMQ 的安全传输
  • uni-app开发
  • 2024社招面经_存储DB广告架构方向
  • android10 系统定制:增加应用锁功能
  • 数据结构----队列
  • 【python】实现对文件夹中的图像连续重命名方法
  • 【nginx 第一篇章】认识一下 NGINX 服务器
  • 【物联网】(防水篇)哪些电子产品需要通过 IPX7 防水级别测试?
  • 高级java每日一道面试题-2024年8月09日-网络篇-什么是XSS攻击如何避免?
  • Linux时间管理:命令与脚本的完美结合
  • 基于ssm+vue+uniapp的微信外卖小程序
  • lvs(linux virtual server)实例
  • Unity游戏开发
  • 5. MQTT消息类型详解(三)
  • TypeScript JSX