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 block of memory to be searched.
2nd Parameter Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
2nd Parameter
The value to search for, converted to an `unsigned char`.
3rd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
3rd Parameter
The number of bytes to examine in the memory block.
Read more about parameters of memchr in parameters section
The memchrfunction in C language Searches for the first occurrence of a character in a block of memory.
The memchr function searches within the first n bytes of the object pointed to by s for the first occurrence of c (interpreted as an unsigned char). The search includes the terminating null character.
The memchrfunction takes 3
parameters:
•
const void * `ptr`: Pointer to the block of memory to be searched.
•
int `value`: The value to search for, converted to an `unsigned char`.
•
size_t `num`: The number of bytes to examine in the memory block.
Searches the first `num` bytes of the memory block pointed to by `ptr` for the first occurrence of the value `value` (interpreted as an `unsigned char`). Returns a pointer to the matching byte, or `NULL` if the value is not found.
The memchr function return value :
Returns a pointer to the located character, or NULL if the character does not occur in the object
Output
This example demonstrates basic usage of memchr to find a character in a string.