Plus: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | 1 | \+ | |
| 4 | - | ||
| 5 | - | ||
| 6 | 2 | ||
| 7 | 3 | The symbol `+` (pronounced “plus”) is used to: | |
| 8 | 4 | ||
| 9 | 5 | - explicitly indicate the positive sign of a number, | |
| 10 | 6 | - add two numbers resulting to a number, | |
| 11 | 7 | - form a union of [[Set|sets]], | |
| 12 | 8 | - (FPC) concatenate two strings (or characters; except [[PChar|pchar]]). | |
| 13 | 9 | - if `{$modeSwitch arrayOperators+}` (default in [[Mode Delphi|{$mode Delphi}]]), concatenate arrays (since FPC 3.2.0) | |
| 14 | 10 | - enable a feature in a `{$modeSwitch}` | |
| 15 | 11 | ||
| 16 | 12 | ``` pascal | |
| 17 | 13 | program plusDemo(input, output, stderr); | |
| 18 | 14 | ||
| 19 | 15 | var | |
| 20 | 16 | x: longint; | |
| 21 | 17 | g: set of (foo, bar); | |
| 22 | 18 | m: string; | |
| 23 | 19 | begin | |
| 24 | 20 | // unary operator: positive sign | |
| 25 | 21 | x := +7; // x becomes positive 7 | |
| 26 | 22 | x := +$100; // x becomes 256 | |
| 27 | 23 | // (dollar sign denotes hexadecimal base) | |
| 28 | 24 | ||
| 29 | 25 | // addition | |
| 30 | 26 | x := 7 + 7; // x becomes 14 | |
| 31 | 27 | x := 7 + 7 + 7 + 7 + 7 + 7; // x becomes 42 | |
| 32 | 28 | ||
| 33 | 29 | // union of sets | |
| 34 | 30 | g := [foo] + [bar]; // g becomes [foo, bar] | |
| 35 | 31 | ||
| 36 | 32 | // concatenation of strings and/or characters (FPC/Delphi extension) | |
| 37 | 33 | m := 'Hello ' + 'world!'; // m becomes 'Hello world!' | |
| 38 | 34 | end. | |
| 39 | 35 | ``` | |
| 40 | 36 | ||
| 41 | 37 | The plus sign is also a unary operator. One can write such stupid expressions as `++++++++++++++42` which will evaluate to positive 42. | |
| 42 | 38 | ||
| 43 | 39 | In [[ASCII]], the character code decimal `43` (or [[Hexadecimal|hexadecimal]] `2B`) is defined to be `+` (plus sign). | |
| 44 | 40 | ||
| 45 | 41 | ## see also | |
| 46 | 42 | ||
| 47 | 43 | - [`system.add`](https://www.freepascal.org/docs-html/rtl/system/.op-add-variant-ariant-ariant.html) | |
| 48 | 44 | - [`system.concat`](https://www.freepascal.org/docs-html/rtl/system/concat.html) returns concatenation of strings | |
| 49 | 45 | - [`strings.strcat`](https://www.freepascal.org/docs-html/rtl/strings/strcat.html) returns concatenation of [[PChar|pchar]] strings | |
| 50 | 46 | ||
| 51 | 47 | --- | |
| 52 | 48 | *From the Free Pascal wiki, page "Plus", as it stood on 2019-10-16 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).* |
