// String character array var arr: array [0 .. 5] of char; STR: string; begin {The String constant can be directly assigned to the character array, but not to the character array.} arr: = 'delphi '; showmessage (ARR ); {Delphi} {the character array can be directly assigned to the string variable} STR: = arr; showmessage (STR); {Delphi} {in fact, the string also contains an array of characters, therefore, the index can be accessed, but its index starts from 1} showmessage (STR [1]); {d} showmessage (ARR [0]); {d} {, but a string variable cannot be assigned to the character array} // arr: = STR; {error; this must be implemented by other means, such as copying or moving the memory} end;
// Character array> character pointer var arr: array [0 .. 6] of char; P: pchar; begin arr: = 'delphi '; {if the character array is directly given to the character pointer, the result is not safe, because the character pointer needs to find a null character (#0) to end} {give #0 the last element of the array.} arr [length (ARR)-1]: = #0; p: = arr; showmessage (p); {Delphi} {What If I gave #0 to the center ?} Arr [3]: = #0; P: = arr; showmessage (p); {del; truncated} end;
// String constant> character array constant
Const arr1: array [0 .. 5] of char = 'delphi '; arr2: array [0 .. 5] of ansichar = ansistring ('delphi '); begin showmessage (arr1 [0]); {d} showmessage (arr2 [0]); {d} end;