Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 4/Parameters: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-4B - Parameters (author: Tao Yue, state: unchanged)
2-
3-A parameter list can be included as part of the procedure heading. The parameter list allows variable values to be transferred from the main program to the procedure. The new procedure heading is:
1+[[Basic Pascal Tutorial/Chapter 4/Procedures|◄]] | [[Basic Pascal Tutorial/Contents|▲]] | [[Basic Pascal Tutorial/Chapter 4/Functions|►]]
2+---|---|---
3+
4+4B - Parameters (author: Tao Yue, state: unchanged)
45
5-``` pascal
6+A parameter list can be included as part of the procedure heading. The parameter list allows variable values to be transferred from the main program to the procedure. The new procedure heading is:
7+```
68procedure Name (formal_parameter_list);
79```
810
9-The parameter list consists of several parameter groups, separated by semicolons:
10-
11-`param_group_1; param_group2; ... ; param_groupn`
12-
13-Each parameter group has the form:
14-
15-`identifier_1, identifier_2, ... , identifier_n : data_type`
11+The parameter list consists of several parameter groups, separated by semicolons:
12+```
13+param_group_1; param_group_2; ... ; param_group_n
14+```
1615
17-The procedure is called by passing arguments (called the actual parameter list) of the same number and type as the formal parameter list.
16+Each parameter group has the form:
17+```
18+identifier_1, identifier_2, ... , identifier_n : data_type
19+```
1820
19-``` pascal
21+The procedure is called by passing arguments (called the actual parameter list) of the same number and type as the formal parameter list.
22+```
2023procedure Name (a, b : integer; c, d : real);
21-begin
22- a := 10;
23- b := 2;
24- writeln (a, b, c, d)
25-end;
24+ begin
25+ a := 10;
26+ b := 2;
27+ writeln (a, b, c, d)
28+ end;
2629```
2730
28-Suppose you called the above procedure from the main program as follows:
29-
30-``` pascal
31+Suppose you called the above procedure from the main program as follows:
32+```
3133alpha := 30;
32-Name (alpha, 3, 4, 5);
34+ Name (alpha, 3, 4, 5);
3335```
3436
35-When you return to the main program, what is the value of alpha? 30. Yet, alpha was passed to a, which was assigned a value of 10. What actually happened was that a and alpha are totally distinct. The value in the main program was not affected by what happened in the procedure.
36-
37-This is called **call-by-value**. This passes the **value** of a variable to a procedure.
37+When you return to the main program, what is the value of `alpha`? 30. Yet, `alpha` was passed to `a`, which was assigned a value of 10. What actually happened was that `a` and `alpha` are totally distinct. The value in the main program was not affected by what happened in the procedure.
3838
39-Another way of passing parameters is **call-by-reference**. This creates a **link** between the formal parameter and the actual parameter. When the formal parameter is modified in the procedure, the actual parameter is likewise modified. *Call-by-reference* is activated by preceding the parameter group with a `VAR`:
39+This is called **call-by-value**. This passes the **value** of a variable to a procedure.
4040
41-``` pascal
42-VAR identifier1, identifier2, ..., identifiern : datatype;
41+Another way of passing parameters is **call-by-reference**. This creates a **link** between the formal parameter and the actual parameter. When the formal parameter is modified in the procedure, the actual parameter is likewise modified. _Call-by-reference_ is activated by preceding the parameter group with a `VAR`:
4342```
44-
45-In this case, constants and literals are not allowed to be used as actual parameters because they might be changed in the procedure.
43+VAR identifier_1, identifier_2, ..., identifier_n : datatype;
44+```
4645
47-Here's an example which mixes *call-by-value* and *call-by-reference*:
46+In this case, constants and literals are not allowed to be used as actual parameters because they might be changed in the procedure.
4847
49-``` pascal
48+Here's an example which mixes _call-by-value_ and _call-by-reference_ :
49+```
5050procedure Name (a, b : integer; VAR c, d : integer);
51-begin
52- c := 3;
53- a := 5
54-end;
55-
56-begin
57- alpha := 1;
58- gamma := 50;
59- delta := 30;
60- Name (alpha, 2, gamma, delta);
61-end.
51+ begin
52+ c := 3;
53+ a := 5
54+ end;
55+
56+ begin
57+ alpha := 1;
58+ gamma := 50;
59+ delta := 30;
60+ Name (alpha, 2, gamma, delta);
61+ end.
6262```
6363
64-Immediately after the procedure has been run, gamma has the value 3 because c was a reference parameter, but alpha still is 1 because a was a value parameter.
64+Immediately after the procedure has been run, `gamma` has the value 3 because `c` was a reference parameter, but `alpha` still is 1 because `a` was a value parameter.
6565
66-This is a bit confusing. Think of call-by-value as copying a variable, then giving the copy to the procedure. The procedure works on the copy and discards it when it is done. The original variable is unchanged.
66+This is a bit confusing. Think of call-by-value as copying a variable, then giving the copy to the procedure. The procedure works on the copy and discards it when it is done. The original variable is unchanged.
6767
68-Call-by-reference is giving the actual variable to the procedure. The procedure works directly on the variable and returns it to the main program.
68+Call-by-reference is giving the actual variable to the procedure. The procedure works directly on the variable and returns it to the main program.
6969
70-In other words, call-by-value is one-way data transfer: main program to procedure. Call-by-reference goes both ways.
70+In other words, call-by-value is a one-way data transfer: main program to procedure. Call-by-reference goes both ways.
7171
72+[[Basic Pascal Tutorial/Chapter 4/Procedures|◄]] | [[Basic Pascal Tutorial/Contents|▲]] | [[Basic Pascal Tutorial/Chapter 4/Functions|►]]
73+---|---|---
74+
7275---
73-*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Parameters", 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).*
76+*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Parameters", as the Internet Archive kept it on 2026-02-11, last changed on 2025-03-01. 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