Difference between revisions of "Variable parameter"
From Lazarus wiki
Jump to navigationJump to search (reword 2nd paragraph) |
|||
Line 34: | Line 34: | ||
== Read more == | == Read more == | ||
− | |||
* [http://lazarus-ccr.sourceforge.net/fpcdoc/ref/refsu48.html Variable parameter] | * [http://lazarus-ccr.sourceforge.net/fpcdoc/ref/refsu48.html Variable parameter] | ||
− | * [[Xor]] | + | * [[Xor|xor]] |
− | * [[If]] | + | * [[Var|var]] |
+ | * [[Out|out]] | ||
+ | * [[If|if]] |
Revision as of 12:55, 17 July 2016
Variable parameter (or Reference Parameter) is an input and output parameter meaning it can be used for passing a value to a function or procedure, as well as to get back a value from a function or procedure. It is indicated by the use of the keyword var in front of the formal parameter.
A variable parameter can be considered a nickname to the actual argument given by the calling routine. When a procedure or function changes the value of a variable parameter they are actually changing the variable in the code that called the function or procedure.
XOR swap
procedure XorSwap( var i,j:integer );
begin
i := i xor j ;
j := i xor j ;
i := i xor j ;
end;
OrderSmallBig
procedure OrderSmallBig( var a,b:integer );
begin
if a > b then XorSwap( a, b );
end;