Sign in Join
Wiki copytemporary

Variable parameter/es

English · Español · Suomi

Un parámetro variable (o parámetro pasado por referencia) es un parámetro de entrada y salida, lo que significa que se utiliza para pasar un valor a la función o al procedimiento y que también sirve para recuperar desde fuera, el valor que dentro de la función o procedimiento ha tomado la variable. Se indica mediante la palabra reservada var delante del parámetro formal.

El nombre del parámetro de la definición es un apodo de la variable que se pasa. El dentro del método se hace referencia a la misma variable y los cambios realizados tienen efecto en la variable actual.

XOR swap

pascal
  
procedure XorSwap(  var i,j:integer );
  begin
    i := i xor j ;
    j := i xor j ;
    i := i xor j ;
  end;

OrderSmallBig

pascal
  
procedure OrderSmallBig( var a,b:integer );
  begin
    if a > b then XorSwap( a, b ); 
    // tras la llamada a tendrá el valor anterior de b y b tendrá el antiguo de a
  end;

Leer también


From the Free Pascal wiki, page "Variable parameter/es", as it stood on 2023-01-25 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.