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++
- How to call some function before main() function in C++?
- What happens when a virtual function is called inside a non-virtual function in C++
- Difference between Virtual function and Pure virtual function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- arc function in C
- fma() function in C++
- iswspace() function in C/C++
- iswblank() function in C/C++
- iswpunct() function in C/C++
- gmtime() Function in C/C++
- iswalpha() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.