Sign in Join
Wiki copytemporary

Equal: what changed

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

OldNewLine
1-<div style="float:right; margin: 0 10px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
2-
31=
4-
5-</div>
62
73The symbol `=` (pronounced “equal”) is used to
84
95- compare two (comparable) values for equality,
106- [[Constant|constant]] declarations (including [[Resourcestring|resourcestring sections]]), and
117- [[Type|type declarations]], as well as
128- specifying [[Default parameter|default values]] for formal parameters in method declarations.
139
1410Furthermore, if [[Enum Type|enumeration data types]] are defined with explicit indices, [[FPC]]’s Delphi compatibility modes require an equal sign instead of [[Becomes|:=]] when specifying the indices.
1511
1612## application
1713
1814``` pascal
1915program equalDemo(input, output, stderr);
2016
2117const
2218 answer = 42;
2319
2420resourcestring
2521 prompt = 'What''s the answer?';
2622
2723type
2824 number = longint;
2925
3026var
3127 i: number;
3228
3329begin
3430 writeLn(prompt);
3531 readLn(i);
3632
3733 if not (i = answer) then
3834 begin
3935 exitCode := 1;
4036 end;
4137end.
4238```
4339
4440Be aware of *what* you compare: When you compare two references, i.e. [[Class|class]] or [[Pointer|pointer]] variables, without dereferencing them first, you usually compare two memory addresses, *not* the actual content at those addresses. Operator overloading may alter this behavior, though. For instance the content of [[Ansistring|ansistrings]] can be compared without any special treatment, though *internally* (transparently) they are realized as pointers.
4541
4642Note, you usually do not use the equal sign comparison in conjunction with [[IEEE 754 formats|floating-point numbers]]. Instead one uses [`math.compareValue`](https://www.freepascal.org/docs-html/rtl/math/comparevalue.html).
4743
4844## comparitive remarks
4945
5046Unlike other programming languages, the symbol is *not* used to assign a value, for that the character pair [[Becomes|:=]] is used. An exception of this are “initialized variables”, where you specify an initial value inside the [[Var|var section]] alongside your [[Variable|variable]] declarations:
5147
5248``` pascal
5349program initializedVariable(input, output, stderr);
5450
5551var
5652 i: longint;
5753 response: string = 'Wrong!';
5854
5955begin
6056 writeLn('What''s the answer?');
6157 readLn(i);
6258
6359 if i = 42 then
6460 begin
6561 response := 'Right!';
6662 end;
6763
6864 writeLn(response);
6965end.
7066```
7167
7268Also, a comparison *always* results in a [[Boolean|boolean value]].
7369
7470## ASCII value
7571
7672In [[ASCII]], the character code decimal `61` (or [[Hexadecimal|hexadecimal]] `3D`) is defined to be `=` (equals sign).
7773
7874## see also
7975
8076- [[Becomes|becomes-operator :=]] assigns values to a variable
8177- [[Not equal|not-equal-operator &lt;&gt;]] checks for inequality
8278
8379---
8480*From the Free Pascal wiki, page "Equal", as it stood on 2020-11-10 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