In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the memory operation functions of C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the memory operation functions of C language?"
Header file: # include1.memcpy
Function: memory copy
Function prototype:
Void * memcpy (void * dest, const void * src, size_t count)
Use:
Format: memcpy (destination, original, memory size you want to manipulate (in bytes))
Copy the "Parameter 3" byte content starting from "Parameter 2" to "Parameter 1"
The memecpy function is similar to strncpy.
Example:
# include # include # include int main () {int aa [] = {1pr 2pc 3P 4}; int bb [10] = {0}; memcpy (bb, aa, 4 * sizeof (int)); / / copy the contents of 4 bytes (each int type is 4 bytes) in the aa array to the bb array for (int I = 0; I)
< 10; i++) //打印bb数组全部数据 { printf("%d ", bb[i]); } } 最后bb字符串中前4*4个字节的内容被改为aa的内容Note: memcpy cannot copy overlapping memory.
# include # include # include int main () {int aa [] = {1, int 2, 3, 5, 5, 6, 8, 9, 10}; my_memcpy (aa + 2, aa, 24); for (int I = 0; I)
< 10; i++) { printf("%d ", aa[i]); }} 输出: 拷贝重叠内存会出现这样的问题。 2.memmove 作用:内存拷贝(可拷贝重叠内存) 原型: void *memmove( void *dest, const void *src, size_t count ); 使用与memcpy一样,只是memmove可以拷贝重叠内存 #include #include #include int main(){ int aa[] = { 1,2,3,4,5,6,7,8,9,10 }; memmove(aa + 2, aa, 24); for (int i = 0; i < 10; i++) { printf("%d ", aa[i]); }} 出: 同样的代码使用memmove就可以. 3.memcmp 作用:内存比较 函数原型: int memcmp( const void *buf1, const void *buf2, size_t count ); 使用: 使用格式:memcmp(地址1,地址2,想要比较的内存大小 单位bit) 逐字节比较内存大小, 逐字节一对一对比较!! 返回值有三种情况: 0 "参数1" 与 "参数2" 逐字节比较时遇到的第一对不同的内存时 "参数1" 中数据 >"Parameter 2".
4.memset
Function: memory settin
Function prototype:
Void * memset (void * dest, int c, size_t count)
Use:
Format: memset (address, a number, how many bytes to set)
Example:
# include int main () {int a [] = {1Jing 2 Jing 3 Jing 4 Jing 5}; memset (a, 1,20); / / change the first 20 bytes starting with a to 1}
Results:
At this point, I believe you have a deeper understanding of the "C language memory operation functions", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.