Look at the following examples:
Char myname[] = {' L ', ' I ', ' s ', ' I '}; Character array <span style= "White-space:pre" > </span> length is 4
char hename[] = {' L ', ' I ', ' s ', ' I ', '/'};//String c3/> length of 5
char yourname[10] = "Xiaoqiang"; String length is 10 although only 9 characters
1 Definition: The string is an array of characters ending with '/'. Note, however, that ' strlen ' does not belong to the length of the string, it can be calculated using the length of the character array, and that sizeof is an operator, not a function. We can use sizeof (myName) to find the length of the character array, when ' s ' is counted.
2 Then, why does the normal array have no placeholders, and the character array has%s.
that we cannot
int num[] = {1, 2, 3};
printf ("%d", num);
<pre name= "code" class= "plain" > also cannot
printf ("%s", myName); After output, the content is:lisi\300\367\277_\377</strong></span></p>
But you can
printf ("%s,%s", YourName, Hename);
Because the string is an array of characters ending with '% ', printf encounters '/' will end the output
A summary is:
Strlen: The length of the string is not included '
sizeof: string lengths (including ' \ S ') and number of character array elements can be obtained