Sign in Join
Wiki copytemporary

Becomes/zh CN

English · Français · Suomi · Русский · 中文(中国)

=

符号 := (符号 冒号 跟着符号 等号, 中间没空格或其他字符) 读作 ***成为(变成)***,在 Pascal 中意思是 被赋值为...:

pascal
 A := 4 ;
 Circle_Area := Pi * Diameter ;
 Name := 'Smith' ;
 C := 1000 - C div 2 ;

使用两个符号,冒号加等号(而不是只用一种,比如说光用=等号)是为了区分赋值与相等比较。

例如,在Pascal以外的语言您可以写

A = B = D ;

或

A = B = D

取决与分号在那种语言中是否必要。

该表达式的含义取决于语言。例如,在Fortran和Basic中,该表达式意思是将A赋值为“B和D相等吗?” 在C语言中,该表达式意思是将变量A和B的值赋值给D。这种类型的指令错误在C语言中再常见不过了以至于这种表达式经常被编译器标识一个警告,除非您通过在表达式两旁加括号告诉编译器您是有意这么做(多重赋值)。在C语言中测试相等的正确做法是使用A = B == D;

在Pascal中这种混淆不会发生的,因为该语句非法。您可以写

pascal
A := B = D;

意思与FORTRAN或BASIC相同,就是将A赋值为“B和D相等吗?”

要将A,B,D赋予相同的值需要显式的分开赋值形式

A := D ; B := D ;

或

B := D ; A := B ;

或

A := D ; B := A ;

取决于在执行中是否有差异或有副作用 (D 可以式一个动态变量,比方说一个系统 port, 一个 函数 或是一个对象 的 属性 ,因此 标识符 D 在第一和第二个赋值示例中可能会有所不同)


From the Free Pascal wiki, page "Becomes/zh CN", as it stood on 2020-02-09 after a change by Trev, 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.

Revision 3, last changed by WikiArchive .

Edited on wiki.freepascal.org by 3 people, 2016–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
WtwangcbCreated page
Wtwangcb (minor)
FTurtle
TrevFixed syntax highlighting (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.