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

How are the two variables related? If the value of one of these variables is changed, what effect is apparent in the other variable?

2006-10-19 14:08:10 · 2 answers · asked by sommers 1 in Computers & Internet Programming & Design

2 answers

yes, it is legal.
Both the variables are local to there methods.So outside the method they have no aspect or their scope is restricted to the
methods in which they are declared.Then if value of one variable in no way affects the other.

good luck.

2006-10-19 22:03:42 · answer #1 · answered by Anand 3 · 3 0

Yes, it is legal. When you declare a local variable inside a method like this:

foo(){
int x;

}

the variable has a "scope" that extends only from the declaration to the closing brace. So, it can't be seen by other methods at all. If other methods have variables named x, those variables will also be entirely separate from the x declared above. This means that changing x has no effect on the value of another variable x declared in another method.

Now, when you pass variables as arguments to methods, it is possible that they may be changed. But you have to make that happen on purpose, and I think you are asking about the "default" behavior.

2006-10-19 14:12:49 · answer #2 · answered by arbeit 4 · 1 0

fedest.com, questions and answers