' BYREF/BYVAL — Parameter passing mechanisms
#COMPILE EXE
#DIM ALL

SUB DoubleByVal(BYVAL x AS LONG)
    x = x * 2
    PRINT "  Inside DoubleByVal: x = " & STR$(x)
END SUB

SUB DoubleByRef(BYREF x AS LONG)
    x = x * 2
    PRINT "  Inside DoubleByRef: x = " & STR$(x)
END SUB

SUB Swap(BYREF a AS LONG, BYREF b AS LONG)
    LOCAL temp AS LONG
    temp = a
    a = b
    b = temp
END SUB

FUNCTION PBMAIN() AS LONG
    LOCAL val AS LONG

    val = 10
    PRINT "Initial value: " & STR$(val)
    PRINT
    CALL DoubleByVal(val)
    PRINT "After DoubleByVal: " & STR$(val)
    PRINT
    CALL DoubleByRef(val)
    PRINT "After DoubleByRef: " & STR$(val)
    PRINT
    PRINT STRING$(40, 45)

    LOCAL x AS LONG
    LOCAL y AS LONG
    x = 100
    y = 200
    PRINT "Before Swap: x=" & STR$(x) & ", y=" & STR$(y)
    CALL Swap(x, y)
    PRINT " After Swap: x=" & STR$(x) & ", y=" & STR$(y)

    FUNCTION = 0
END FUNCTION
