std::memchr in C++ Last Updated : 29 May, 2023 Comments Improve Suggest changes Like Article Like Report C++ offers various standard template library functions to be used. One of them is memchr() function which is used to search for the first occurrence of a character in a specified number of characters. memchr() is defined inside <cstring> header file. Syntax of memchr()const void* memchr( const void* ptr, int ch, std::size_t count );Parametersptr: Pointer to the object where the search will be performed.ch: Character to search for.count: Number of characters to be searched for.Return ValueIf the character is found, the memchr() function returns a pointer to the location of the character otherwise,If the character is not found, it returns the NULL Pointer.Examples of memchr()Example 1 The following C++ program illustrates the use of memchr() function to search for a character in a string. C++ // CPP program to illustrate memchr() #include <cstring> #include <iostream> using namespace std; int main() { // defining string and a character char sr[] = "This is a sample"; char ch = 's'; int count = 13; // using memchr to check for the presence of 's' in sr if (memchr(sr, ch, count)) cout << ch << " is present in first " << count << " characters of \"" << sr << "\""; else cout << ch << " is not present in first " << count << " characters of \"" << sr << "\""; return 0; } Outputs is present in first 13 characters of "This is a sample"Example 2 The following C++ program illustrates the use of memchr() function to search for a character in an array of characters. C++ // CPP program to illustrate memchr() #include <cstring> #include <iostream> using namespace std; int main() { char arr[] = { 'b', 'a', 'd', 'e', 'f', 'A', 'g' }; // checking the presence of 'g' char* pc = (char*)memchr(arr, 'g', sizeof arr); if (pc != NULL) cout << "search character found\n"; else cout << "search character not found\n"; } Outputsearch character found Comment More infoAdvertise with us Next Article std::memchr in C++ P pranav gupta Improve Article Tags : Misc C++ STL CPP-Library Practice Tags : CPPMiscSTL Similar Reads std::memcmp() in C++ memcmp() function compares the first count bytes ( given number of characters ) of the memory pointed to by buf1 and buf2. memcmp() is a Standard Library function defined in <string.h> header file in C++. Syntaxint memcmp(const void *buf1, const void *buf2, size_t count);Parametersbuf1: Pointe 3 min read Memset in C++ C++ memset() is a function that copies a single character for a specified number of times to the given bytes of memory. It is useful for filling a number of bytes with a given value starting from a specific memory location.Example:C++#include <bits/stdc++.h> using namespace std; int main() { c 5 min read memcpy() in C The memcpy() function in C is defined in the <string.h> header is a part of the standard library in C. The memcpy() function is used to copy a block of memory from one location to another. Example: C#include <stdio.h> #include <string.h> // For memcpy int main() { // Initialize a v 2 min read Memory Model in C++ 11 Memory Model is a specification that describes how the program interacts with the memory. In C++ 11, a standardized memory model is created to provide the solution to issues surrounding concurrency, ordering, and multithreading. This framework specifies how memory is accessed and arranged in a C++ p 5 min read std::quoted in C++ 14 std::quoted is an I/O manipulator function that was introduced in C++ 14 as the part of <iomanip> library. Its primary purpose is to handle the quoted string in the input and output operations. In this article, we will learn about the std::quoted manipulator, how it works and how to use it in 5 min read Like