Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c
programming

How to use strrev in C

Educative Answers Team

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;
}
C program to demonstrate the function strrev(). Please note strrev() is non-standard and may not be available.

Output:

eeffoc

RELATED TAGS

c
programming
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring