Implement the inversion function, that is, to reverse a string ending with null

Source: Internet
Author: User
1 # include <iostream> 2/* 3 to implement the inversion function, that is, to reverse a string ending with null. 4 Note: if no additional space is allocated, the string is reversed directly, in addition, pay attention to the concept of null character 6: 7 1. first, calculate the length of the string. The calculated length contains null. Therefore, the calculated value is equal to or equal to 1 8 2. exchange two characters from the beginning and end of the string until the pointer meets 9 */10 11 using namespace STD; 12 Void reverse (char * Str) 13 {14 char * end = STR; 15 char TMP; 16 if (STR) 17 {18 while (* End) 19 {20 + + end; 21} 22 -- end; 23 while (STR <End) 24 {25 TMP = * STR; 26 * STR ++ = * end; 27 * end -- = TMP; 28} 29} 30} 31 32 int main () 33 {34 char s [] = {'A', 'B', 'C'}; 35 cout <S <Endl; 36 reverse (s ); 37 cout <S <Endl; 38 return 0; 39}

 

Implement the inversion function, that is, to reverse a string ending with null

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.