Difference between revisions of "Byte/fr"

From Free Pascal wiki
Jump to navigationJump to search
Line 28: Line 28:
 
</delphi>
 
</delphi>
  
{{Data types}}
+
{{Data types/fr}}
  
 
[[category:Pascal]]
 
[[category:Pascal]]

Revision as of 16:56, 8 July 2007

Deutsch (de) English (en) español (es) suomi (fi) français (fr) italiano (it) русский (ru) 中文(中国大陆)‎ (zh_CN)

A byte is an unsigned integer in the range of 0 .. 255. A byte and a char are the same thing, except a byte can only be referred to as a numeric type, while a char can be used as a character, or as part of a string type, and cannot be used in an arithmetic expression.

For example: <delphi>

Var c: byte; 
ch: char;
begin
  c := 65;  ch := 'A';  { are the same action, and are legal }
  c := 'A'; ch := 65;   { while they are the same action, this is illegal }
end.

</delphi>

The use of byte or char as a data type provides better documentation as to the purpose of the use of the particular variable. The byte type can be coerced to char by using the chr function. Char type values can be coerced to byte by using the ord function

The above program corrected to legal use:

<delphi>

Var c: byte; 
ch: char;
begin
  c := 65;  ch := 'A'; { are the same action, and are legal }
  c := ord('A'); ch := Chr(65); { now legal }
end.

</delphi>

Types de données
Types de données simples Boolean | Byte |Cardinal | Char | Currency | Extended | Int64 | Integer | Longint | Pointer | Real | Shortint | Smallint | Word
Types de données complexes Array | Class | Record | Set | String | ShortString