There is no special string variable in C language, and a character array is usually used to store a string. When we first introduced a String constant, it indicates that the string is always'/0' is the end of the string. Therefore, when a string is saved to an array, the terminator '/0' is also saved to the array as a flag for whether the string ends. With the '/0' sign, you do not need to use the length of the character array to determine the length of the string.
The C language allows the array to be initialized and assigned a value using a string.
For example:
Char C [] = {'C', '', 'P', 'R', 'O', 'G', 'R', 'A ', 'M '};
It can be written as follows:
Char C [] = {"C program "};
Or remove {} and write it:
Char C [] = "C program ";
The value assignment in string mode occupies one byte more than the value assignment in characters one by one. It is used to store the string ending mark.'/0 '. The actual storage of array C in the memory is as follows:
'/0' is automatically added by the C compilation system. Because of'/0' flag. Therefore, when you use a string to assign an initial value, you do not need to specify the length of the array.
Measure the string length function.Strlen
Format:Strlen (character array name)
Function: test the actual length of a string (excluding the end mark of the string ).'/0') As the return value of the function.