Sign in Join
Wiki copytemporary

Revision 3 of 4, by Kai Burghardt on 8-20-2022. The page as it is now.

Basic Pascal Tutorial/Chapter 4/Scope/zh CN

4D - ��作用域 (原作者: Tao Yue, 状�: 未更改)

��作用域是指��的使用范围。

全局��,指在主程�中定义的��。

它的作用范围:任何�程��以使用�修改。

过程(函数)中定义的��如果与全局����,则它是局部��,�仅在过程(函数)中有效。

这里的�点是:

pascal
代��(过程�函数等等)中,��作用域是,�内定义,�内��。
pascal
program ScopeDemo;
var A : integer;

  procedure ScopeInner;
  var A : integer;
  begin
    A := 10;
    writeln (A)
  end;

begin (* Main *)
  A := 20;
  writeln (A);
  ScopeInner;
  writeln (A);
end. (* Main *)

程�输出结果是:

pascal
20
10
20

原因是:

pascal
定义å�Œå��å�˜é‡�多次,如,在主程åº�ã€�å­�程åº�都定义的相å�Œå��ç§°çš„å�˜é‡�,它们调用æ—,都将调用自己的。

这是一个��作用域图表,通过�缩进�以很清楚看到��的使用范围。

上一页 目录 下一页

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Scope/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.