Questions tagged [local-variables]

Local variables have a limited scope, generally one function or one functional block.

Local variables have a limited scope, generally one function or one functional block.

Compare with global variables, which are accessible from any part of a program.

1302 questions
-1
votes
1 answer

Java convention--naming a local variable the same as field

Writing a program that interprets a line from a text file. Wondering if I should be naming the local variables in method 'parseWordData' something likescannedWord as oppposed to word, because word is already a class field. as long as I am declaring…
-1
votes
3 answers

When does Global Variables take preference over Function Scoping in Javascript?

Case 1: The following Code alerts 10 as it should: var globalId='10'; function check(){ alert(globalId); } check(); Case 2: But this next code alerts undefined: var globalId='10'; function check(){ alert(globalId); var…
Naruto
  • 1
  • 1
-1
votes
1 answer

Animate CC HTML5 canvas: how do I create a private/local variable in Actionscript?

I'm using a variable to create a toggle-effect on a function. The only problem is that this code changes the variable globally, and not locally for each object using the function. I know what I have to do, just not how :) Function: var…
Carl Papworth
  • 1,282
  • 2
  • 16
  • 35
-1
votes
2 answers

How can I change a local variable assigned to the value of a global one without changing the global variable?

So this is basically how the code works that I'm using. global Gvar Gvar = ["Hello"] def someFunction(): Lvar = Gvar Lvar.append("World") print(Lvar) print(Gvar) someFunction() This outputs "Hello World" twice. How can I prevent…
-1
votes
1 answer

Function can't recognize global variable

I wrote a python script that displays the covered distance of a projectile based on its speed and angle. However, it doesn't read those two variables that another function (ask_values()) returned from the user. What prevents the covered_distance()…
Larry
  • 1,312
  • 2
  • 15
  • 22
-1
votes
2 answers

What is the default value of arrays in java?

if local variables need to be assigned some default value then why java provide default value for arrays declared locally. import java.util.Arrays; import java.util.Scanner; public class MatrixMultiplication { int a; int a1[][]=new int[2][2]; …
Ankit
  • 95
  • 1
  • 9
-1
votes
1 answer

How actually applicationServlet manages context varibles?

How actually applicationServlet manages context varibles ? If I set variables in applicationContext level whether it stores in Method area or stack area or heap , if so how it stored and how its accessed ? Here i created local variable as MAP and…
Suman Behara
  • 150
  • 9
-1
votes
1 answer

How to pass a local variable to a user-defined function in pandas?

I am processing a pandas dataframe df. Depending on certain conditions within df, I want to pass df (1) either to the user defined function filter() or (2) to calculate_Result(). The code for the condition is: if df.Col1.str.contains("yes").sum() >…
sudonym
  • 3,788
  • 4
  • 36
  • 61
-1
votes
1 answer

local variables in C

when I try the following code in visual studio it gives me 45 but when I run it in online compilers some give me an error and some give me 0.I was expecting that they all give me an error.how is that they are not?! thanks #include int…
-1
votes
1 answer

How to access Local variables of functions when the function call has finished in python?

I found on the net that local variables of functions can't be accessed from outside when the function call has finished.I try to execute the program but it throws an error that variable is not defined. My code is xyz=list() n=0 def length(g): …
Chirag Dhingra
  • 128
  • 2
  • 17
-1
votes
1 answer

How do I print the sum outside the loop ? I think there's some mistake in deceleration of global and local variable

When I put the 6th last line (cout << "rank : " << sum + 1 << endl;) outside the loop it says that sum was not declared in this scope. The code is right below : #include #include #include #include using…
-1
votes
1 answer

Personality test via JS alone?

I am wanting to make a character personality test(for my fictional characters) I know I am going to have to have variables equaling arrays like this: // var personality = [gender, age, muscularity, trait_1, trait_2, etc.]; I know the variable =…
Caters
  • 147
  • 1
  • 10
-1
votes
2 answers

Are variables for pass by value variables and local variables in a function not allocated continuously?

I want to know the way variables are allocated on stack, so i make a small test program #include #include using namespace std; class test { public: test() { } test(const test &obj) { cout << "a…
Hai Hoang
  • 1,207
  • 2
  • 18
  • 35
-1
votes
1 answer

Naming a file with a variable in a shell script

I'm writing a unix shell script that sorts data in ten subdirectories (labelled 1-10) of the home directory. In each subdirectory, the script needs to rename the files hehd.output and fort.hehd.time, as well as copy the file hehd.data to a .data…
Rhyphte
  • 3
  • 2
-1
votes
1 answer

Reuse Class Level Variables or Create New Local Variables?

I've seen this question asked many times, but in different ways and the answer has never been what I've been looking for. I'm sure I could do some tests, but I feel like this could be a good resource for others and maybe get some opinions on the…