C language--The calculation method of string length
Tip: (1) It is important to recognize the escape character when calculating the length of the string, and (2) an escape character will always start with a backslash, plus one other character. Therefore, you should pay special attention when you encounter the backslash!!! 1. A string without an escape character such as "abc!x=/" with a length of 7
2. String with escape character
(1) string "abc\n": where ' \ n ' is an escape character (line break), the length of a string can only be counted as one character, so the length of the string is 4 (not 5)
(2) The string "abc\n\\\" ": There are 4 escape characters: ' \ n ' (newline character), ' \ \ ' (backslash), ' \ ' (single quote), ' \ ' (double quotation mark), so the length of the string is 7 (instead of 11). (3) string "ABC\0XYZ": There is an escape character ' \ s ', which is a string terminator, so when the length of the string is tested with the function strlen, the result should be 3 (not 7). (4) The string "Abc\\0xy": where there is an escape character ' \ \ ' (backslash), so that the string "0xy" after the same calculation, so that the length of the string is 7 (instead of the second backslash and the subsequent 0 is combined into an escape character ' "", if so, The first backslash will not be processed because a
C language--The calculation method of string length