Basic Pascal Tutorial/Chapter 1/Constants/zh CN: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Basic Pascal Tutorial/Chapter 1/Constants/zh CN
| Old | New | Line | |
|---|---|---|---|
| 1 | + | 1C - 常量 (原作者: Tao Yue, 状态: 未更改) | |
| 2 | + | ||
| 3 | + | 常量通过标识符来引用,它只能在程序开始的时候被初始化为某个确定的值。常量中存储的值是无法更改的。 | |
| 4 | + | ||
| 5 | + | 常量只能在程序的常量说明部分定义: | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | const | |
| 9 | + | Identifier1 = value; | |
| 10 | + | Identifier2 = value; | |
| 11 | + | Identifier3 = value; | |
| 12 | + | ``` | |
| 13 | + | ||
| 14 | + | 例如,我们来定义一些各种类型的常量:字符串类型,字符类型,整数类型,实数类型和布尔类型。这些数据类型在下一页会解释。 | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 17 | + | const | |
| 18 | + | Name = 'Tao Yue'; | |
| 19 | + | FirstLetter = 'a'; | |
| 20 | + | Year = 1997; | |
| 21 | + | pi = 3.1415926535897932; | |
| 22 | + | UsingNCSAMosaic = TRUE; | |
| 23 | + | ``` | |
| 24 | + | ||
| 25 | + | 注意,在Pascal中字符是用单引号(')括起来的!这跟那些允许使用双引号或Heredoc符号的新语言不同。标准Pascal并不允许使用双引号来标记字符或字符串。 | |
| 26 | + | ||
| 27 | + | 如果你要定义一个在程序中到处都会用到,而且以后可能还需要更改的值,常量就非常有用。需要更改值的时候,你只需要在常量的定义处修改就行了,不用把程序中所有引用都一一更改。 | |
| 28 | + | ||
| 29 | + | 强类型常量会强制成为指定数据类型的常量。例如: | |
| 30 | + | ||
| 31 | + | ``` pascal | |
| 32 | + | const | |
| 33 | + | a : real = 12; | |
| 34 | + | ``` | |
| 35 | + | ||
| 36 | + | 这将会产生实数值12.0的标识符,而不是整数值12的标识符。 | |
| 37 | + | ||
| 38 | + | | | | | | |
| 39 | + | |----|----|----| | |
| 40 | + | | [[Basic Pascal Tutorial/Chapter 1/Identifiers/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 1/Variables and Data Types/zh CN|下一页]] | | |
| 41 | + | ||
| 42 | + | --- | |
| 43 | + | *From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Constants/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](/wiki-contact).* | |
| 44 | + | Category: zh |
