memcpy: Copies a specified number of bytes from one memory location to another.


void *memcpy(void *dest, const void *src, size_t n);
memmove: Similar to memcpy, but handles overlapping memory regions correctly.


void *memmove(void *dest, const void *src, size_t n);
memset: Sets a specified number of bytes in a memory region to a given value.


void *memset(void *s, int c, size_t n);
memcmp: Compares two memory regions.


int memcmp(const void *s1, const void *s2, size_t n);

These four functions (memcpy, memmove, memset, and memcmp) are commonly 
used for low-level memory operations in C. They allow you to copy, move,
set, and compare blocks of memory, respectively.

---------------------------------------------------------------------------------------------------------


The memory functions (memcpy, memmove, memset, and memcmp) in C are primarily used for handling
blocks of memory. While they are commonly associated with string manipulation, they are not limited 
to strings and can be used for any arbitrary blocks of memory, including arrays of various types.

Here are some general use cases:

Copying Data:

memcpy: Used to copy a specified number of bytes from one memory location to another. This can be 
useful for duplicating data structures, creating backups, or copying arrays.
Moving Data:

memmove: Similar to memcpy but handles overlapping memory regions correctly. It is useful when the 
source and destination regions overlap, as it ensures a safe and correct copy.
Setting Values:

memset: Used to set a specified number of bytes in a memory region to a given value. This is often
used to initialize memory to a known state, such as zeroing out an array.
Comparing Data:

memcmp: Compares two memory regions. It returns an integer less than, equal to, or greater than zero
if the first block of memory is found to be less than, equal to, or greater than the second block, 
respectively.
These functions are not limited to strings but are commonly used in string operations due to C's 
representation of strings as null-terminated character arrays. However, they can be applied to any 
type of data represented in memory.

For example, if you have an array of integers, you can use memcpy or memmove to copy or move the data,
    memset to initialize the array to a specific value, and memcmp to compare two arrays of integers.


#include <stdio.h>
#include <string.h>

int main() {
    int arr1[] = {1, 2, 3, 4, 5};
    int arr2[5];

    // Copying data
    memcpy(arr2, arr1, sizeof(arr1));

    // Displaying the copied array
    for (int i = 0; i < 5; i++) {
        printf("%d ", arr2[i]);
    }

    return 0;
}
In this example, memcpy is used to copy the contents of arr1 to arr2. The functions memmove, memset, 
and memcmp can be similarly applied to manipulate arrays of any type.

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: