strrev() function in C

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:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

The given string is =geeksforgeeks
After reversing string is =skeegrofskeeg

Example 2:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

The given string is = 123456789
After reversing string is = 987654321


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.