当前位置:网站首页>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;
}边栏推荐
- [network] cross area network communication learning classification and calculation of IPv4 address
- Data system of saltstack
- JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
- What is the process of swing event processing?
- C language function
- Source code analysis of scripy spider
- shared_ PTR and make_ Use of shared
- Edge detection and connection of image segmentation realized by MATLAB
- MySQL command statement (personal summary)
- Redis notes
猜你喜欢

Basic knowledge of communication network 01

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

How does app automated testing achieve H5 testing

Cloud computing notes part.2 - Application Management

Prometheus deployment

Article translation software - batch free translation software supports major translation interfaces

Getting started with enterprise distributed crawler framework

JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver

Concurrent programming, do you really understand?

云计算笔记part.1——系统管理
随机推荐
党员故事|李青艾用漫画带动农民增收致富
Redis master-slave architecture (how to calculate sizeof function)
[wechat applet development] page navigation and parameter transmission
English Translation Spanish - batch English Translation Spanish tools free of charge
克服“看牙恐惧”,我们用技术改变行业
[network] communication across regional networks learn how routing tables work
个人博克系统登录点击图形验证码的集成与实现
云计算笔记part.2——应用管理
leetcode day3 超过经理收入的员工
Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
KPMG China: insights into information technology audit projects of securities fund management institutions
C language functions and pointers
English translation Arabic - batch English translation Arabic tools free of charge
Why is there no log output in the telnet login interface?
Andorid system layout, values, drawable adaptation
Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
Prometheus deployment
[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
并发程序设计,你真的懂吗?
Saltstack advanced