Basic Pascal Tutorial/Chapter 4/Functions/zh CN
Sent here from Functions/zh CN.
English · Français · Български · 中文(中国) · 日本語
4C - 函数 (原作者: Tao Yue, 状态: 未更改)
函数的工作方式和过程相似;不同的是,函数总要有返回值,通过给函数名赋值确定返回值。
function Name (????????????) : ????????????;过程不能直接参与运算,函数可以。在表达式中使用函数进行运算:
a := Name (5) + 3;如果你的函数没有参数,要注意不要在右侧的功能内的任何公式使用函数的名称。是:
如果定义的函数没有参数,不要在函数体内部使用与函数名相同的名称:
function Name : integer;
begin
Name := 2;
Name := Name + 1
end.这是被禁止的,想像一下,无限递归调用自己……
通过给函数名赋值来设置返回值。
Name := 5;函数最好不要使用按引用(地址)传递参数——函数应该只有一个返回值。
你肯定不希望使用sin函数时,却改变了pi值吧?它的结果只为0。
| 上一页 | 目录 | 下一页 |
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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
