Difference between revisions of "Char"
(Missed two 64's) |
(reword comment) |
||
Line 10: | Line 10: | ||
begin | begin | ||
ch := 'A'; c := 65; { are the same action, and are legal } | ch := 'A'; c := 65; { are the same action, and are legal } | ||
− | ch := 65; c := 'A'; { while they are the same | + | ch := 65; c := 'A'; { while they are internally the same values, direct assignment between Chars and Bytes is illegal } |
end. | end. | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 08:40, 11 June 2016
│
Deutsch (de) │
English (en) │
español (es) │
français (fr) │
italiano (it) │
русский (ru) │
A char is a single character. A byte and a char are the same thing, except a char can be used as a character, or as part of a string type, and cannot be used in an arithmetic expression, while a byte can only be referred to as a numeric type.
For example:
var ch: char;
c: byte;
begin
ch := 'A'; c := 65; { are the same action, and are legal }
ch := 65; c := 'A'; { while they are internally the same values, direct assignment between Chars and Bytes is illegal }
end.
The use of char or byte as a data type provides better documentation as to the purpose of the use of the particular variable. The char type can be coerced to byte by using the ord function. Byte type values can be coerced to char by using the chr function.
type chars functions follows the ASCII.
The above program corrected to legal use:
var ch: char;
c: byte;
begin
ch := 'A'; c := 65; { are the same action, and are legal }
ch := chr(65); c := ord('A'); { now legal }
c := Byte('A'); { also legal and guaranteed to happen at compile time }
end.
See also
- Character and string types, a detailed reference covering internal memory layout and access options.
simple data types |
|
---|---|
complex data types |