1. C Language
In C language, there is basically no difference between a string and a character array, and both require Terminator; for example, char s [4] = {'A', 'B', 'C ', 'D '}; the definition of this character array can be compiled, but the array is not closed. If you need to apply for Memory later, all future data will be placed in it, although it is not long enough, if it is Char s [5] = {'A', 'B', 'C', 'D '}; the system automatically stores an ending character at the end of the string and closes the array, indicating that the character array has an ending character;
The length defined by the string must be greater than the length of the Character Sequence, for example, char S1 [4] = {"ABCD"}. Compilation fails, it should be written as char S1 [5] = {"ABCD"}; and the system will automatically store an terminator at the end of the string, indicating that the string has an Terminator;
Use the strlen () function in the C language to test the length of the array. The strlen () function does not contain the terminator '/0 '.
Char s [5] = {'A', 'B', 'C', 'D '};
Char S1 [5] = {"ABCD "};
Int A = strlen (s );
Int B = strlen (S1 );
The result is a and B is 4;
2. Java language
The Terminator is not required for both string and string arrays;
For example, char [] value = {'J', 'A', 'V', 'A', 'yu', 'yan '};
String S1 = new string (value );
String S2 = "Java language ";
Int A = value. length;
Int B = s1.length ();
Int c = s2.length ();
The running result A, B, and C are both 6, indicating that the Terminator is not required for both the string and string arrays. But pay attention to the value here. length and s1.length (). The length of an array object can be recorded by the famous Constant Length in the array. Length () is an instance method in the file class and is used to return the file size, of course, you can also return the size of the string.