Sign in Join
Wiki copytemporary

Equal

English · Français · Suomi · Русский

=

The symbol = (pronounced “equal”) is used to

Furthermore, if enumeration data types are defined with explicit indices, FPC’s Delphi compatibility modes require an equal sign instead of := when specifying the indices.

application

pascal
program equalDemo(input, output, stderr);

const
    answer = 42;

resourcestring
    prompt = 'What''s the answer?';

type
    number = longint;

var
    i: number;

begin
    writeLn(prompt);
    readLn(i);
    
    if not (i = answer) then
    begin
        exitCode := 1;
    end;
end.

Be aware of what you compare: When you compare two references, i.e. class or 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 ansistrings can be compared without any special treatment, though internally (transparently) they are realized as pointers.

Note, you usually do not use the equal sign comparison in conjunction with floating-point numbers. Instead one uses math.compareValue.

comparitive remarks

Unlike other programming languages, the symbol is not used to assign a value, for that the character pair := is used. An exception of this are “initialized variables”, where you specify an initial value inside the var section alongside your variable declarations:

pascal
program initializedVariable(input, output, stderr);

var
    i: longint;
    response: string = 'Wrong!';

begin
    writeLn('What''s the answer?');
    readLn(i);
    
    if i = 42 then
    begin
        response := 'Right!';
    end;
    
    writeLn(response);
end.

Also, a comparison always results in a boolean value.

ASCII value

In ASCII, the character code decimal 61 (or hexadecimal 3D) is defined to be = (equals sign).

see also


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.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.