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

What does it mean to pass a variable to a method by value?

2007-03-26 10:25:07 · 3 answers · asked by TheOne 1 in Computers & Internet Programming & Design

3 answers

well... there are two types of function calls, you can call either by passing a value or by passing a variable to it

for example you have a function to add two numbers
its like
int add(int x, int y)
{
return x+y;
}

when u call it like
z=add(a,b);
its called as call by referance

and when u call it like
z=add(400,600)
its called as call by value

in the first case u r passing the variable(ie., referance) to the function and in the second case u r passing the values(400 and 600) directly to the function.

2007-03-26 11:45:51 · answer #1 · answered by Arul 2 · 0 0

Pass by value means a copy of the argument's value is passed into the parameter variable. You can also pass by reference which allows a function for example to access the parameter's original argument.

2007-03-26 17:44:55 · answer #2 · answered by lslbyd 2 · 0 0

It means as opposed to by reference.

When you pass by reference, any alterations to the variable affect the original variable that was passed in. If you pass by value, the value is merely copied to a new variable and the original is safe from alteration.

2007-03-26 17:30:38 · answer #3 · answered by Fabian 2 · 0 0

fedest.com, questions and answers