memcpy(內存拷貝函數)簡介


效果:實現內存拷貝

參數:第一個參數是一個指針,指向拷貝目標區域;第二個參數是一個指針,指向被拷貝的內存區域;第三個參數是一個數,指定拷貝內容的內存大小

函數原型:void *memcpy(void* str1, const void* str2, size_t n)

頭文件:#include<string.h>

返回值:指向str1的指針(這里的str1即函數原型中的str1)

 1 #include <bits/stdc++.h> 
 2 
 3 using namespace std;  4 
 5 int main()  6 {  7     int str1[6];  8     int str2[6];  9     for(int i = 0; i < 6; i++){ 10         str2[i] = i; 11  } 12     cout << "str2:"; 13     for(int i = 0; i < 6; i++){ 14         cout << " " << str2[i]; 15  } 16     cout << endl; 17     memcpy(str1, str2, sizeof(str2)); 18     cout << "str1:"; 19     for(int i = 0; i < 6; i++){ 20         cout << " " << str1[i]; 21  } 22 }

運行結果為:

str2: 0 1 2 3 4 5 str1: 0 1 2 3 4 5

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM