Arguments

From GMpedia.org Wiki

Jump to: navigation, search

Arguments are variables that are passed to a function or script when it is called. They influence the output of the function.

//function call statement
function(arguments);

[edit] By value / By reference

Arguments can be passed by value or by reference.

  • Pass by value: when the function is called, a copy of the passed argument is made and all changes to the copy will not affect the original variable.
  • Pass by reference: when the function is called, a reference to the actual variable is passed and all changes to the argument will change the original variable. The name of the argument in the function becomes an alias for the variable.

Default, arguments are passed by value. To indicate that a variable should be passed by reference, the following keywords or symbols can be added in the function definition:

//C++
int function(&a); //the & sign indicates that the first argument will be passed by value
                  //a is the alias for the variable
'Visual Basic
Private Function(ByRef a) As Integer
End Function



This article is a stub, please help GMpedia expand it.
Personal tools