English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

In Visual BASIC 6, the default is ByRef, which passes the MEMORY ADDRESS (NOT the ACTUAL VALUE) of the variable. This means that the content of the memory address can change and the code using the variable wouldn't know about it. If you pass a variable ByVal (you have to explicitly code the ByVal keyword) then the code using the variable knows that the value of the variable has changed.

2007-01-19 07:22:10 · answer #1 · answered by Richard H 7 · 1 0

When a variable is passed to a function, it can be passed one of two ways. The first way, "by value", means that the function is told what the value of the variable is. It can change that value but the value of the original variable will stay the same. The second, "by reference," means that the function is given a pointer to the variable - meaning, it is given the location where the variable's value is stored. So if it changes the value of the variable, the value will be changed for any other function that later uses that variable.

Different programming languages handle this in different ways, and sometimes some types of variables (like numbers or string) are passed by value and others (like objects or pointers) by reference. It is an important thing to understand in whatever programming language you use.

I included a couple of links below, under Sources, that might be helpful.

2007-01-19 06:52:15 · answer #2 · answered by Tamara K 2 · 2 0

In call by value memory is allocated for the parameters in the function stack frame. This means you can assign to those variables without changing the value in the calling function.

In call by reference the variables passed refer to the actual memory location of the variables. This means if you assign to the variable in the subroutine the variable in the calling function will have the new value.

In C, the difference is done by using the address operator:

void byValue(int x) {
printf("v1: X is %d\n", x);
x++;
printf("v2: X is %d\n", x);
}

void byRef(int *x) {
printf("r1: X is %d\n", *x);
(*x)++;
printf("r2: X is %d\n", *x);
}

main() {
int x = 4;
printf("1: X is %d\n", x);
byValue(x);
printf("2: X is %d\n", x);
byRef(&x);
printf("3: X is %d\n", x);
}

Output will be:
1: X is 4
v1: X is 4
v2: X is 5
2: X is 4
r1: X is 4
r2: X is 5
3: X is 5

2007-01-19 06:57:58 · answer #3 · answered by sofarsogood 5 · 1 0

In CALL by value you are importing the CURRENT value Of X directly.

X=10

A+X=Y

In CALL by reference you are importing the current value of X by it's memory address.

A+ADDRESS OF X = Y

2007-01-20 16:45:59 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers