C++ cstring memchr() function
Example
Get a pointer to the first byte in a block of memory which contains a specified value:
char myStr[] = "Hello World!";
char * myPtr = (char*)memchr(myStr, 'o', 12);
cout << myPtr;
Try it Yourself »
Definition and Usage
The memchr()
function returns a pointer to the first byte in a block of memory which contains a specified value.
The memchr()
function is defined in the <cstring>
header file.
Note: The memchr()
function is generalized for memory of any type. When working with C-style strings (char
arrays) it is better to use the strchr()
function instead.
Syntax
memchr(void * pointer, int value, size_t size);
The size_t
data type is a positive integer.
Parameter Values
Parameter | Description |
---|---|
pointer | Required. A pointer to the block of memory to search in. |
value | Required. The value to search for. |
size | Required. The size of the block of memory to search in. |
Technical Details
Returns: | A void type pointer to the position in memory where the value was found or a NULL pointer if the value was not found. |
---|