A pointer to a constant memory location of unspecified type. The pointed-to data cannot be modified through this pointer.
1st Parameter
Pointer to the first block of memory to compare.
2nd Parameter Type : const void *
A pointer to a constant memory location of unspecified type. The pointed-to data cannot be modified through this pointer.
2nd Parameter
Pointer to the second block of memory to compare.
3rd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
3rd Parameter
The number of bytes to compare between the two memory blocks.
Read more about parameters of memcmp in parameters section
The memcmpfunction in C language Compares two blocks of memory.
The memcmp function compares the first n bytes of the object pointed to by s1 to the first n bytes of the object pointed to by s2. The comparison is done lexicographically, treating the bytes as unsigned char values.
The memcmpfunction takes 3
parameters:
•
const void * `ptr1`: Pointer to the first block of memory to compare.
•
const void * `ptr2`: Pointer to the second block of memory to compare.
•
size_t `num`: The number of bytes to compare between the two memory blocks.
Compares the first `num` bytes of the memory blocks pointed to by `ptr1` and `ptr2`. Returns a negative value if the first differing byte in `ptr1` is less than the corresponding byte in `ptr2`, zero if the blocks are equal, or a positive value if the first differing byte in `ptr1` is greater than the corresponding byte in `ptr2`.
The memcmp function return value :
Returns an integer less than, equal to, or greater than zero if the first n bytes of s1 is found, respectively, to be less than, to match, or be greater than the first n bytes of s2
Output
This example demonstrates basic usage of memcmp to compare two strings.