Home>Article>Backend Development> What are memory operations in C language?

What are memory operations in C language?

王林
王林 forward
2023-08-26 13:05:08 1034browse

What are memory operations in C language?

Library #include contains basic memory operations. Although not strictly string functions, the prototypes of these functions are declared in #include .

These memory operations are as follows:

##void *memchr (void *s, int c, size_t n); In the buffer Search characters in . int memcmp (void *s1, void *s2, size_t n); Compare two buffers. void *memcpy (void *dest, void *src, size_t n); Copy one buffer to another buffer. void *memmove (void *dest, void *src, size_t n); Move a certain number of bytes from one buffer to another . void *memset (void *s, int c, size_t n); Sets all bytes of the buffer to the given characters.
Note that in all cases bytes of memory are copied. The sizeof() function comes in handy again.

memcpy(dest, src, SIZE); Copy characters (bytes) memcpy( idest, isrc, SIZE*sizeof(int)); Copy integer array

##
memmove() behaves in exactly the same way as memcpy() except, that the source and destination locations may overlap.

memcmp() is similar to strcmp() except here, unsigned bytes are compared and returns less than zero if si is less than s2 etc.

For example,

char src[SIZE], dest[SIZE]; int isrc[SIZE], idest[SIZE];

The above is the detailed content of What are memory operations in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete