当前位置:网站首页>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;
}
边栏推荐
- 云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
- MySQL8 Encrypting InnoDB Tablespaces
- leetcode day3 超过经理收入的员工
- [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
- Cloud computing notes part.1 - system management
- Redis笔记
- Serial port receiving application ring buffer
- Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
- Know small and medium LAN WLAN
- NPM installing and uninstalling global packages
猜你喜欢
Read how to deploy highly available k3s with external database
Getting started with enterprise distributed crawler framework
How many types of rain do you know?
Intermediate soft test (system integration project management engineer) high frequency test site
English translation Arabic - batch English translation Arabic tools free of charge
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
A chip company fell in round B
leetcode day1 分数排名
Function fitting based on MATLAB
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
随机推荐
Saltstack advanced
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
Source insight project import and use tutorial
[网络]跨区域网络的通信学习IPv4地址的分类和计算
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
This customized keyboard turns me on~
架构基本概念和架构本质
English Translation Spanish - batch English Translation Spanish tools free of charge
基于MATLAB的函数拟合
Redis notes
In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
MySQL command statement (personal summary)
爬取IP
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
河北:稳粮扩豆助力粮油生产提质增效
C language functions and pointers
There are five certificates in the soft examination advanced examination, which is more worth taking?
Source code analysis of scripy spider
KPMG China: insights into information technology audit projects of securities fund management institutions
Edge detection and connection of image segmentation realized by MATLAB