Difference between revisions of "Equal"

From Free Pascal wiki
Jump to navigationJump to search
m (style)
(rename →‎example: to →‎application: ; mention handling with [[rename →‎example)
Line 8: Line 8:
 
* specifying [[Default parameter|default values]] for formal parameters in method declarations.
 
* specifying [[Default parameter|default values]] for formal parameters in method declarations.
  
== example ==
+
== application ==
 
<syntaxhighlight lang="pascal" highlight="4,7,10,19">
 
<syntaxhighlight lang="pascal" highlight="4,7,10,19">
 
program equalDemo(input, output, stderr);
 
program equalDemo(input, output, stderr);
Line 38: Line 38:
 
Operator overloading may alter this behavior, though.
 
Operator overloading may alter this behavior, though.
 
For instance the content of [[Ansistring|<syntaxhighlight lang="pascal" enclose="none">ansistring</syntaxhighlight>s]] can be compared without any special treatment, though ''internally'' (transparently) they are realized as pointers.
 
For instance the content of [[Ansistring|<syntaxhighlight lang="pascal" enclose="none">ansistring</syntaxhighlight>s]] can be compared without any special treatment, though ''internally'' (transparently) they are realized as pointers.
 +
 +
IEEE 754 formats
  
 
== comparitive remarks ==
 
== comparitive remarks ==

Revision as of 01:42, 22 November 2018

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

=

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

application

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.

IEEE 754 formats

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:

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


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)