Sign in Join
Wiki copytemporary

*

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

*

standard Pascal

The symbol *, pronounced “asterisk”, is used in Pascal to

pascal
program asteriskDemo(input, output, stderr);

type
    day = (monday, tuesday, wednesday,
        thursday, friday, saturday, sunday);

var
    i: longint;
    n: real;
    m: set of day;

begin
    // multiplication operator
    i := 6 * 7;      // i becomes 42
    n := 6.0 * 7.0;  // n becomes 42.0
    
    // intersection operator
    m := [saturday, sunday] * [sunday, monday];
    // m is now {sunday}
end.

exponentiation

Furthermore, in FPC the exponentiation operator consisting of two consecutive asterisks ** exists. However, it is only defined for variants by the standard system unit, which requires a variant manager being installed. In order to actually use it with integers, one can define it on their own:

pascal
program exponentiation(input, output, stdErr);

// make operator overloading available
{$mode objFPC}

operator ** (const base: integer; const exponent: integer): integer;
begin
    if base <> 0 then
    begin
        result := trunc(exp(ln(base) * exponent));
    end;
end;

begin
    writeLn(2 ** 10); // will print 1024
end.

For readily available overloads, the math and matrix unit can be included.

other appearances

In Pascal's years of childhood computer systems did not necessarily knew the comment delimiting characters opening and closing curly brace { }. To make block comments available on such systems an alternative syntax, the bigramms (* and *) are allowed, too, but they can't be interchanged willynilly: (* has to match a *), and can not match a } even though it is closing a block comment, too.

Also, if C like operators were allowed by the compiler directive {$COperator on}, the short syntax for i := i * n reads i *= n. But by doing so, you leave the domain of Pascal. Your code technically, mathematically speaking becomes wrong.

In ASCII, the character code decimal 42 (or hexadecimal 2A) is defined to be *.


From the Free Pascal wiki, page "", as it stood on 2022-11-27 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 1, last changed by WikiArchive .

Talk about this page

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