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