Skip to content
Related Articles

Related Articles

strrev() function in C

View Discussion
Improve Article
Save Article
  • 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!