The strrchr() function in C/C++ locates the last occurrence of a character in a string. It returns a pointer to the last occurrence in the string. The terminating null character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string. It is defined in cstring header file.
const char* strrchr( const char* str, int ch ) or char* strrchr( char* str, int ch )
Parameter :The function takes two mandatory parameters which are described below:
- str : specifies the pointer to the null terminated string to be searched for.
- ch: specifies the character to be search for.
Return Value: The function returns a pointer to the last location of ch in string, if the ch is found. If not found, it returns a null pointer.
Below programs illustrate the above function:
Last position of k in Geeks for Geeks is 13
z is not present in Geeks for Geeks
- strrchr() function in C/C++
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- exp() function C++
- log() function in C++
- fma() function in C++
- arc function in C
- div() function in C++
- feupdateenv() function in C++
- raise() function in C++
- iswlower() function in C/C++
- fread() function in C++
- tellg() function in C++ with example
- wcstombs() function in C++ STL
- Address of a function in C or C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.