el:ref [BASIC 256 - Language Documentation]

# BASIC 256 - Language Documentation

el:ref

## Ref

### Format

subroutine subroutinename ( ref(variable),variable )
call subroutinename ( ref(variable),variable )
function functionname ( ref(variable),variable )
functionname ( ref(variable),variable )

### Description

By default values are passed to Subroutines and Functions by value. This means that the value that you specify when calling the routine is copied into a variable that belongs to and is totally local to the routine.
The ref() declaration allows you to pass a reference to a variable or an array to the routine. When a routine changes the value of a referenced variable, the change is actually made to the original variable used in the routine call.

### Example

    dim a(10)
    call assignarray(ref(a),10)
    print "total="+totalarray(ref(a),10)
    end
    subroutine assignarray(ref(array), arraylen)
       # set array elements
       for t = 0 to arraylen-1
          array[t]= t*t
        print array[t]
       next t
    end subroutine
    function totalarray(ref(array),arraylen)
       totalarray = 0
       for t = 0 to arraylen-1
          totalarray += array[t]
       next t
    end function

displays

    0
    1
    4
    9
    16
    25
    36
    49
    64
    81
    total=285

### See Also

Begin Case / Case / End Case, Call, Continue Do, Continue For, Continue While, Do / Until, End, Exit Do, Exit For, Exit While, For / Next, Function, Global, Goto, Gosub, If Then, Pause, Ref, Rem, Return, Subroutine, While / End While

### New To Version

0.9.9.13

el/ref.txt · Last modified: 2014/01/11 23:26 (external edit)