what is the Simple and Easiest Explanation about ByRef & ByVal in FreeBASIC. I already read the FreeBASIC Manual but still don't get it.
the only basic that I know is the Simple Print, If-Else-Select Case, Do-Loop, For Loop & simple GUI using FbGfx.bi. thank you in advance :)
ByRef, ByVal, Sub, & Function
-
- Posts: 5
- Joined: Nov 05, 2018 8:55
Re: ByRef, ByVal, Sub, & Function
Have you read these documentation pages?
- Procedures Overview
- Passing Arguments to Procedures (read the paragraph 'Manually passing pointers to by-reference parameters' is optional, because it's just a punctual advanced feature)
- Returning Values (read the paragraph 'Manually returning pointers as-is from Byref functions' is optional, because it's just a punctual advanced feature)
- Procedures Overview
- Passing Arguments to Procedures (read the paragraph 'Manually passing pointers to by-reference parameters' is optional, because it's just a punctual advanced feature)
- Returning Values (read the paragraph 'Manually returning pointers as-is from Byref functions' is optional, because it's just a punctual advanced feature)
Last edited by fxm on Jun 26, 2019 11:07, edited 2 times in total.
-
- Posts: 5
- Joined: Nov 05, 2018 8:55
Re: ByRef, ByVal, Sub, & Function
not yet. but ill check it. newbie here. thank you fxm
Re: ByRef, ByVal, Sub, & Function
Here a simple example using function only. It's the same with sub except there is no return value.
Code: Select all
Function TestVal(x As Integer) As Integer
x += 1
Return x
End Function
Function TestRef(ByRef x As Integer) As Integer
x += 1
Return x
End Function
Dim As Integer x = 0
? "Value x: " & x, "Return value from function: " & TestVal(x)
? "Value x after function call: " & x
?
x = 0
? "Value x: " & x, "Return value from function: " & TestRef(x)
? "Value x after function call: " & x
Sleep
Re: ByRef, ByVal, Sub, & Function
ByVal: the procedure (Sub/Function) gets a copy of the original variable.What is the simple and easiest explanation about ByRef & ByVal in FreeBASIC.
(original remains "as-is", unchanged even if modified inside procedure!)
ByRef: the procedure (Sub/Function) references the original variable.
(changes made to it, remain permanent)