当前位置:网站首页>Implementation of memcpy in C language
Implementation of memcpy in C language
2022-07-28 20:01:00 【Hello_ World_ two hundred and thirteen】
One .memcpy Introduce
void* memcpy ( void* dest, const void* src, size_t num );
size_t num --- Unit is byte ( How many bytes to copy )
void* Can receive any type of address , But it cannot be dereferenced or ++--
Be careful :memcpy Cannot overlap copies
Two .memcpy Use
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main()
{
int i = 0;
int arr1[] = { 1,2,3,4,5 };
int arr2[5] = { 0 };
memcpy(arr2, arr1, sizeof(arr1));
for (i = 0; i < 5;i++)
{
printf("%d\n", arr2[i]);
}
return 0;
}3、 ... and .memcpy The implementation of the
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
void* my_memcpy(void* dest, const void* src, size_t num)
{
void* ret = dest;
assert(dest != NULL);
assert(src != NULL);
while (num--)
{
*(char*)dest = *(char*)src;
(char*)dest+=1;
(char*)src+=1;
}
return ret;
}
int main()
{
int i = 0;
int arr1[] = { 1,2,3,4,5 };
int arr2[5] = { 0 };
my_memcpy(arr2, arr1, sizeof(arr1));
for (i = 0; i < 5;i++)
{
printf("%d\n", arr2[i]);
}
return 0;
}边栏推荐
- Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
- Leetcode day3 employees who exceed the manager's income
- 11、 学习MySQL UNION 操作符
- Netcoreapi operation excel table
- Basic usage of docker
- shared_ PTR and make_ Use of shared
- 数字滤波器设计——Matlab
- The United States will provide $25billion in subsidies to encourage chip manufacturers such as Intel to move back to production lines
- C language array and bubble sort
- There are five certificates in the soft examination advanced examination, which is more worth taking?
猜你喜欢

11、 学习MySQL UNION 操作符

Concurrent programming, do you really understand?

Idea properties file display \u solution of not displaying Chinese

认识中小型局域网WLAN

中国能否在元宇宙的未来发展中取得突破,占领高地?

11. Learn MySQL union operator

What parameters should be passed in calling integer or character array functions

基于MATLAB的函数拟合

Android-第十三节03xUtils-数据库框架(增删改查)详解

Know small and medium LAN WLAN
随机推荐
Intermediate soft test (system integration project management engineer) high frequency test site
软考高级考试中有五大证书,哪个更值得考?
leetcode day5 删除重复的电子邮箱
通信网络基础知识01
This customized keyboard turns me on~
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
[in depth study of 4g/5g/6g topics -44]: urllc-15 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -9-low delay technology -3-non slot scheduling mini
11、 学习MySQL UNION 操作符
Failed to install app-debug. apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]
NetCoreAPI操作Excel表格
爬取IP
2022年下半年系统集成项目管理工程师认证8月20日开班
[NPP installation plug-in]
Design of air combat game based on qtgui image interface
C language functions and pointers
基于QTGUI图像界面的空战游戏设计
How does app automated testing achieve H5 testing
English translation Arabic - batch English translation Arabic tools free of charge
MySQL8 基于clone创建主从复制
“中国网事·感动2022”二季度网络感动人物评选结果揭晓