How to use strrev in C

strrev() is a non-standard C library function, sometimes found in <string.h>, that is used to reverse a string. For instance, ‘coffee’, when passed to the function, will output ‘eeffoc.’

svg viewer

Note: Being non-standard means that strrev() may not be available. So, you may have to write your own function to reverse a string.

The function is defined as:

char *strrev(char *str);

Code

The usage of strrev() is illustrated below:

#include<stdio.h>
#include<string.h>
int main() {
char str[20] = "coffee";
printf("String before strrev(): %s\n",str);
strrev(str);
printf("String after strrev(): %s\n",str);
return 0;
}

Output:

eeffoc

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved