passvarptr.bmx 405 B

123456789101112131415161718192021
  1. ' This function takes the pointer to an integer variable
  2. ' and adds 1 by treating the variable's memory as an array...
  3. Function AddToVariable (addee:Int Ptr)
  4. addee [0] = addee [0] + 1
  5. End Function
  6. ' Test variable, looking forward to a brave new world...
  7. a = 5
  8. ' Pass the address of 'a' to function...
  9. AddToVariable (VarPtr (a))
  10. ' The result...
  11. Print "Variable a was 5... now it's " + a