Plus

From Lazarus wiki
Jump to navigationJump to search

English (en) suomi (fi) français (fr) русский (ru)

+

The symbol + (pronounced “plus”) is used to:

  • explicitly indicate the positive sign of a number,
  • add two numbers resulting to a number,
  • form a union of sets,
  • (FPC) concatenate two strings (or characters; except pchar).
  • if {$modeSwitch arrayOperators+} (default in {$mode Delphi}), concatenate arrays (since FPC 3.2.0)
  • enable a feature in a {$modeSwitch}
program plusDemo(input, output, stderr);

var
	x: longint;
	g: set of (foo, bar);
	m: string;
begin
	// unary operator: positive sign
	x := +7;                    // x becomes positive 7
	x := +$100;                 // x becomes 256
	                            // (dollar sign denotes hexadecimal base)
	
	// addition
	x := 7 + 7;                 // x becomes 14
	x := 7 + 7 + 7 + 7 + 7 + 7; // x becomes 42
	
	// union of sets
	g := [foo] + [bar];         // g becomes [foo, bar]
	
	// concatenation of strings and/or characters (FPC/Delphi extension)
	m := 'Hello ' + 'world!';   // m becomes 'Hello world!'
end.

The plus sign is also a unary operator. One can write such stupid expressions as ++++++++++++++42 which will evaluate to positive 42.

In ASCII, the character code decimal 43 (or hexadecimal 2B) is defined to be + (plus sign).

see also


navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)
$ (dollar sign)  •  & (ampersand)  •  # (hash)
' (single quote)

character pairs

<> (not equal)  •  <= (less than or equal)  •  := (becomes)  •  >= (greater than or equal)

 •  >< (symmetric difference)  •  // (double slash)