Sign in Join
Wiki copytemporary

Var: what changed

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

Title: Var

OldNewLine
1+The [[Keyword|keyword]] `var` is used to:
2+
3+- start section of [[Variable|variable]] declarations, and
4+- declare a formal parameter as penetrating mutable.
5+
6+## Variable declaration section
7+
8+In a [[Block|block]] the word `var` starts a section of one or more variable [[Declaration|declarations]].
9+
10+``` pascal
11+var
12+ age: integer;
13+```
14+
15+Variables bearing the same [[Type|data type]] can be grouped, by separating their respective [[Identifier|identifiers]] by a [[Comma|comma]]:
16+
17+``` pascal
18+var
19+ firstName, lastName, address: string;
20+```
21+
22+## Variable parameter
23+
24+The word `var` prior a formal parameter declaration indicates that this [[Variable parameter|parameter is variable]], that means assigning values to it will affect the named parameter at the call site.
25+
26+``` pascal
27+procedure censor(var xxx: longWord);
28+begin
29+ if (xxx = $4655434B) or (xxx = $6675636B) then
30+ begin
31+ xxx := $2A2A2A2A;
32+ end;
33+end;
34+```
35+
36+After invoking `procedure censor` the value of the variable that was supplied at the call site (i. e. where the procedure was called) will (possibly) have changed, too.
37+
38+## See also
39+
40+- [[Const|const]]
41+
42+---
43+*From the Free Pascal wiki, page "Var", as it stood on 2021-07-04 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