Sign in Join
Wiki copytemporary

Revision 1 of 1, by WikiArchive on 11-4-2026. The page as it is now.

Basic Pascal Tutorial/Chapter 4/Functions/zh CN

4C - 函数 (原作者: Tao Yue, 状态: 未更改)

函数的工作方式和过程相似;不同的是,函数总要有返回值,通过给函数名赋值确定返回值。

pascal
function Name (�数列表) : 返回类型;

过程不能直接参与运算,函数可以。在表达式中使用函数进行运算:

pascal
a := Name (5) + 3;

如果你的函数没有参数,要注意不要在右侧的功能内的任何公式使用函数的名称。是:

如果定义的函数没有参数,不要在函数体内部使用与函数名相同的名称:

pascal
function Name : integer;
begin
  Name := 2;
  Name := Name + 1
end.

这是被禁止的,想像一下,无限递归调用自己……

通过给函数名赋值来设置返回值。

pascal
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.