4
strrev() function in C
source link: https://www.geeksforgeeks.org/strrev-function-in-c/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Improve Article
strrev() function in C
- Difficulty Level : Medium
- Last Updated : 04 Oct, 2018
The strrev() function is a built-in function in C and is defined in string.h header file. The strrev() function is used to reverse the given string.
Syntax:
char *strrev(char *str);
Parameter:
- str: The given string which is needed to be reversed.
Returns: This function returns the string after reversing the given string.
Note: This is a non-standard function that works only with older versions of Microsoft C.
Below programs illustrate the strrev() function in C:
Example 1:-
// C program to demonstrate
// example of strrev() function
#include<stdio.h>
#include<string.h>
int
main()
{
char
str[50] =
"geeksforgeeks"
;
printf
(
"The given string is =%s\n"
,str);
printf
(
"After reversing string is =%s"
,strrev(str));
return
0;
}
Output:
The given string is =geeksforgeeks After reversing string is =skeegrofskeeg
Example 2:-
// C program to demonstrate
// example of strrev() function
#include<stdio.h>
#include<string.h>
int
main()
{
char
str[50] =
"123456789"
;
printf
(
"The given string is =%s\n"
,str);
printf
(
"After reversing string is =%s"
,strrev(str));
return
0;
}
Output:
The given string is = 123456789 After reversing string is = 987654321
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK