What are memory operations in C language?

CServer Side ProgrammingProgramming

The library #include <memory.h> contains the basic memory operations. Although not strictly string functions, the functions are prototyped in #include <string.h>.

These memory operations are as follows −

void *memchr (void *s, int c, size_t n);Search for a character in a buffer.
int memcmp (void *s1, void *s2, size_t n);Compare two buffers.
void *memcpy (void *dest, void *src, size_t n);Copy one buffer into another.
void *memmove (void *dest, void *src, size_t n);Move a number of bytes from one buffer to another.
void *memset (void *s, int c, size_t n);Set all bytes of a buffer to a given character.

Note that in all case to bytes of memory are copied. The sizeof() function comes in handy again.

memcpy(dest, src, SIZE);Copy chars (bytes)
memcpy(idest, isrc, SIZE*sizeof(int));Copy arrays of ints

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];
Updated on 02-Sep-2021 13:20:50