C/C++ 中的 memmove() 函数
memmove() 函数用于将整个内存块从一个位置移动到另一个位置。其一是源,其二是目标,由指针指向。这在 C 语言中“string.h”头文件里声明。
以下是在 C 语言中 memmove() 的语法:
void *memmove(void *dest_str, const void *src_str, size_t number)
在此处,
dest_str − 指向目标数组。
src_str − 指向源数组。
number − 从源复制到目标的字节数。
以下是在 C 语言中 memmove() 的示例:
示例
#include <stdio.h>
#include <string.h>
int main () {
char a[] = "Firststring";
const char b[] = "Secondstring";
memmove(a, b, 9);
printf("New arrays : %s\t%s", a, b);
return 0;
}输出
New arrays : SecondstrngSecondstring
在上述程序中,初始化了两个 char 类型的数组,memmove() 函数将源字符串“b”复制到目标字符串“a”。
char a[] = "Firststring"; const char b[] = "Secondstring"; memmove(a, b, 9);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP