Example 1 — Basic memchr()
Find character b.
#include <cstring>
#include <iostream>
int main() {
char buf[] = "abc";
const void* p = std::memchr(buf, 'b', 3);
if (p) {
std::cout << *static_cast<const char*>(p) << '\\n';
}
return 0;
} How It Works
- Search examines three bytes.
- Match pointer refers to
'b'. - Cast and print that character.

