C programming string.h function - void *memchr(const void *str, int c, size_t n)

The memchr() function is a string.h library function in C programming language, used to search for a specific character within the first n bytes of a given memory block pointed to by str.

The function signature is:

void *memchr(const void *str, int c, size_t n);
S‮ruo‬ce:www.theitroad.com

The function takes three arguments:

  1. str - a pointer to the memory block to be searched.
  2. c - the character to be located. It is passed as an int, but usually it is the ASCII value of the character.
  3. n - the maximum number of bytes to be searched.

The function returns a pointer to the first occurrence of the character c in the memory block pointed to by str. If the character is not found, the function returns a null pointer.

Note that the return type is void *, which means that the pointer can be cast to any other pointer type without a cast operator or data loss.