Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 4/Functions/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 4/Functions/zh CN

OldNewLine
1+4C - 函数 (原作者: Tao Yue, 状态: 未更改)
2+
3+函数的工作方式和过程相似;不同的是,函数总要有返回值,通过给函数名赋值确定返回值。
4+
5+``` pascal
6+function Name (参数列表) : 返回类型;
7+```
8+
9+过程不能直接参与运算,函数可以。在表达式中使用函数进行运算:
10+
11+``` pascal
12+a := Name (5) + 3;
13+```
14+
15+如果你的函数没有参数,要注意不要在右侧的功能内的任何公式使用函数的名称。是:
16+
17+如果定义的函数没有参数,不要在函数体内部使用与函数名相同的名称:
18+
19+``` pascal
20+function Name : integer;
21+begin
22+ Name := 2;
23+ Name := Name + 1
24+end.
25+```
26+
27+这是被禁止的,想像一下,无限递归调用自己……
28+
29+通过给函数名赋值来设置返回值。
30+
31+``` pascal
32+Name := 5;
33+```
34+
35+函数最好不要使用按引用(地址)传递参数——函数应该只有一个返回值。
36+
37+你肯定不希望使用sin函数时,却改变了pi值吧?它的结果只为0。
38+
39+| | | |
40+|----|----|----|
41+| [[Basic Pascal Tutorial/Chapter 4/Parameters/zh CN|上一页]] | [[Basic Pascal Tutorial/Contents/zh CN|目录]] | [[Basic Pascal Tutorial/Chapter 4/Scope/zh CN|下一页]] |
42+
43+---
44+*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Functions/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).*

Back to history