Sign in Join
Wiki copytemporary

Revision 2 of 3, by Kai Burghardt on 8-20-2022. The page as it is now.

Basic Pascal Tutorial/Chapter 5/Subranges/zh CN

5B - �界类型 (原作者: Tao Yue, 状�: 未更改)

如果我们定义一个��i为integer类型,那么i的值在微型机系统的pascal中,使用2字节的定义表示法,�值范围为-32768~32767;而事实上,�个程�中所用的��的值都有一个确定的范围;例如:人的年龄一般�超过150;一个�级的学生�超过100人;一年中的月数�超过12;一月中的天数�超过31,等等。

如果我们能在程�中对所用的��的值域作具体规定的�,就便于检查出那些��法的数�,这就能更好地��程��行的正确性;而且在一定程度上还会节�内存空间。   

pascal
最低值 .. 最高值
pascal
å…中最低值称为å­�界的下界,最高值称为å­�界的上界。
pascal
下界和上界必须是�一顺�类型(该类型称为�界类型的基类型),且上界的��必须大于下界的��。

如,你声明一周以�一周天数:

pascal
type
  DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
                Thursday, Friday, Saturday);
  DaysOfWorkWeek = Monday..Friday;

你也�以使用字符或整数在�界类型中。

�考

算法与程�设计:PASCAL枚举��界类型

上一页 目录 下一页

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 5/Subranges/zh CN", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.