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