当前位置:网站首页>Implementation of memmove in C language
Implementation of memmove in C language
2022-07-28 20:01:00 【Hello_ World_ two hundred and thirteen】
One .memmove Introduction to
void* memmove ( void* dest, const void* src, size_t num );
and memcpy The difference is that memmove The source and target memory blocks processed by the function can overlap
If the source space and the target space overlap , Then use memmove Function processing
Two .memmove The implementation of the
#include<stdio.h>
#include<assert.h>
void* my_memmove(void* dest, const void* src, size_t count)
{
assert(dest && src);
void* ret = dest;
if (src > dest)
{
while (count--)
{
*(char*)dest = *(char*)src;
(char)dest += 1;
(char)src += 1;
}
}
else
{
while (count--)
{
*((char*)dest + count) = *((char*)src + count);
}
}
return ret;
}
void test_my_memmove()
{
int a[] = { 1,2,3,4,5,6,7,8,9,10 };
my_memmove(a, a+2, 20);
//my_memmove(a+2, a, 20);
for (int i = 0; i < 10; i++)
{
printf("%d ", a[i]);
}
printf("\n");
}
int main()
{
test_my_memcpy();
return 0;
}边栏推荐
- MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
- The opening price soared by 215%! Domestic signal chain chip enterprise Xinhai Technology landed on the scientific innovation board
- Netcoreapi operation excel table
- Know small and medium LAN WLAN
- MySQL命令语句(个人总结)
- English translation Italian - batch English translation Italian tools free of charge
- MySQL8 tmp_table_size和max_heap_table_size
- English translation Arabic - batch English translation Arabic tools free of charge
- Cloud computing notes part.2 - Application Management
- English Translation Spanish - batch English Translation Spanish tools free of charge
猜你喜欢
![[wechat applet development] page navigation and parameter transmission](/img/10/76b6592fa9e71073831887c4fb6da9.png)
[wechat applet development] page navigation and parameter transmission

Source insight project import and use tutorial

editor.md中markdown编辑器的实现

Handan, Hebei: expand grassroots employment space and help college graduates obtain employment

Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)

远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作

Intermediate soft test (system integration project management engineer) high frequency test site

How navicate modifies the database name

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

克服“看牙恐惧”,我们用技术改变行业
随机推荐
leetcode day1 分数排名
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
【NPP安装插件】
Const pointer of C language and parameter passing of main function
The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
克服“看牙恐惧”,我们用技术改变行业
C language functions and pointers
Leetcode Day5 delete duplicate email
Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)
Cell review: single cell methods in human microbiome research
MySQL8 Status Variables: Internal Temporary Tables and Files
河北:稳粮扩豆助力粮油生产提质增效
[wechat applet development] page navigation and parameter transmission
Common APIs in string
What is the process of swing event processing?
How many types of rain do you know?
Oracle insert数据时字符串中有‘单引号问题
Implementation of markdown editor in editor.md
Redis notes
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages