Just for curiosity,
Why in Delphi, if we defined an empty char by:
a:Char;
a:='';
we get an error: Incompatible types: 'Char' and 'string'
However, if we placed
a:='a';
it will be fine?
Is it necessary to define an empty char by: a:=#0?
A char is a single (that is, exactly one) character. So 'a', '∫', and '⌬' are all OK, but not 'ab' (a two-character string), 'Hello World!' (a twelve-character string), or '' (a zero-character string).
However, the NULL character (#0) is a character like any other.
In addition, the character datatype is implemented as a word (in modern versions of Delphi), that is, as two bytes. If all these values 0, 1, ..., 2^16 - 1 are used for real characters, how in the world would you represent your 'empty char'?
'' synonymously with #0, but I would find that confusing. In addition, does it really take that much longer to write #0 than ''?Char and String literals. It may make coding easier, but it also causes confusion like this. I use C++ primarily, and it uses single quotes for characters and double quotes for strings. More explicit, and intuitive to me.'' is simply the empty string, and it is perfectly legal to use that combination, like in ShowMessage(''). But the empty string consists of zero characters, so it is not a character.There is no such thing as an empty char. A char has to have a value. It is an ordinal type, a simple value type. Just as an integer, say, always has a value, so does a char.
The value #0 is not an empty char, it is the character with value 0, commonly known as NUL.
ordinal type.
Ordinaltypes, includingInteger,Char,Byte, and the rest, while they might have some sentinel (flag) or zero values (#0) for Char, for example, can not be "empty" or "null". Since strings and arrays are not Ordinal types the rules are different. A string is like a "dynamic array of characters".''constant expression. It is of typestringand not compatible with typechar. In contrary'a'is compatible. So, you have to define "empty char" convention.