Small string knowledge point

Source: Internet
Author: User

Small string knowledge point (continuous update)

1. Differences between sizeof () and strlen () in calculating the length of a string

1> size of space occupied by string calculated by sizeof (); sizeof is commonly used to calculate the size of custom struct

2> the actual length of the string calculated by strlen (), but does not include the final string end flag '\ 0 '.

Example: Char A [20] = {"hello "};

Sizeof (A) = 20;

Strlen (A) = 5;

2. char s [] = {"123" "123"} is equivalent to Char s [] = {"123123"}. In the string, double quotation marks, other Symbols do not take effect or are empty. If you want to output other symbols, they must be combined with escape characters.

3. When processing strings, Use Pointer arrays instead of two-dimensional arrays. I will not talk much about the benefits. Let's take a look at the program below and

Char * test [] = {"tiger ",

"Welcome ",

"Tigerjibo ",

"Tigerjohn ",

};

Char test [4] [10] = {"tiger", "welcome", "tigerjibo", "tigerjohn "};

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.