Argument Passing By Reference - QBasic

  • When the argument is sent by reference, the address of each variable is copied to the procedure's variable and the changes made in the procedure's variable will affect on the variables used at the called program.

  • Eg: A program to find the sum of the square of the digits in given number.
DECLARE SUB sum (n)
CLS
INPUT "Enter the ending value of the series"; n
PRINT "The value of n before calling the SUB procedure is "; n
CALL sum (n)
PRINT "The value of n after the completion of the SUB procedure is "; n
END

SUB sum (n)
s = 0
WHILE n <> 0
    r = n MOD 10
    s = s + r ^ 2
    n = n \ 10
WEND
PRINT "The sum of the square of the digits is "; s
END SUB

  • Explanation: 
    • Here, if the user run the program giving the value 45, the output value of n before calling the SUB procedure will be 45.
    • And the value of s will be 41.
    • And the value of n after the completion of SUB procedure will be 0.

Share :

Twitter

Random Posts

Back To Top

facebook main

counter

Powered by Blogger.