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);

更新於: 2020 年 6 月 26 日

434 檢視

開啟您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.