C language Strrev () function: string inverse (reverse, reverse)

Source: Internet
Author: User

Header files: #include <string.h>

The Strrev () function resets the string to its prototype:
Char *strrev (char *str);

"Parameter description" STR is the string to reverse.

Strrev () resets the string that Str refers to.

Return value returns a pointer to the inverted string.

Strrev () does not generate a new string, but instead modifies the original string. So it can only reverse the character array, not the string that the string pointer points to, because the string pointer points to a string constant, and the constant cannot be modified.

Function example to see if Strrev () changes the original string.

#include <stdio.h> #include <string.h>int main () {    //changed to char *str1 = "ABCXYZ"; The program crashes at run time.    char str1[] = "ABCXYZ";    Char *ret1 = Strrev (str1);    printf ("The Origin string of str1 is:%s\n", str1);    printf ("The reverse string of STR1 is:%s\n", ret1);    return 0;}

Operation Result:
The origin string of str1 is:abcxyz
The reverse string of str1 IS:ZYXCBA

C language Strrev () function: string inverse (reverse, reverse)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.