![]() |
VOOZH | about |
The strrchr() function in C locates the last occurrence of a character in a string and returns a pointer to it. It is a standard library function defined inside <string.h> header file.
Syntax :
char* strrchr( char* str, int chr );
Parameter:
Return Value:
Example:
Last occurrence of k in GeeksforGeeks is at index 11
strrchr() function returns a NULL pointer if the searched character is not found in the given string.
Example:
z is not present Geeks for Geeks
Time Complexity: O(n),
Space Complexity: O(1),
where n is the length of the string.
Note: NULL character is also treated same as other character by strrchr() function, so we can also use it to find the end of the string.