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
-3
votes
2 answers

Why does it say UnboundLocalError: local variable 'max_range' referenced before assignment When i have assigned it

Why does it say "name 'max_range' is not defined" when I have already assigned it. this is an attempt at a question on https://www.algoexpert.io/questions/Largest%20Range example array: array = [1, 11, 3, 0, 15, 5, 2, 4, 10, 7, 12, 6] def…
Mehul
  • 115
  • 6
-3
votes
1 answer

java default local object variable initialization

In java OCA book Oracle Certified Associate Java SE 8 Programmer there's this QCM: (Chap 1 question number 12) A local variable of type Object default to null they respond that's false. but I think that's a mistake because when we declare this…
Anas Hadhri
  • 159
  • 1
  • 2
  • 9
-3
votes
1 answer

Local variable is not assigning data to global variable javascript

I have a function which returns data to getDates(), after processing i want the data in a global variable but it's not working. var bookedDates=[]; function getDates(result) { var bookedDates1=result.split(","); var bookedDates2=[]; …
-3
votes
3 answers

'for' loop summation in ruby

I am trying to sum array values. Here's my code: def addArray(array) for i in array do sum += i end end addArray([1,3,6,8,7,10]); What's wrong with this thought process? I know there are other ways to do this such as using reduce or even…
Rob
  • 63
  • 1
  • 14
-3
votes
2 answers

Why JavaScript shows "undefined" alert in the 1st line of of r() in the below snippet?

Why JavaScript shows "undefined" alert in the 1st line of of r() in the below snippet?
-3
votes
2 answers

why 2 different strings have the same address in C?

Code and example csv file below. The Program I write is a csv reader. In the while loop I acquire the line of the file as a string and then with sscanf I extract the data that I store in local variables. I have 2 strings that I store in char* name…
dxp
  • 9
  • 1
  • 5
-3
votes
1 answer

What does it mean when constant local variables are stored in the assembly data region, while non-constant local variables are stored on the stack?

I'm reading through this wikibook and don't understand what this means within the local variables section? An ELI5 would be helpful <3
faceless
  • 436
  • 1
  • 4
  • 11
-3
votes
2 answers

Python - Two Classes's Variables Are Linked

I noticed this problem in something I was making, and managed to reproduce it in a simpler form. The problem is that I have two players - both of a Person class - and they each have their own grid. I start off with a global grid variable and assign…
Woafer
  • 11
  • 1
  • 4
-3
votes
2 answers

What would happen if an object is created in non-static method of class in java?

class Data { int x = 20; // instance variable public void show() // non-static method { Data d1 = new Data(); // object of same class Data int x = 10; System.out.println(x); // local x …
Gagan
  • 103
  • 1
  • 1
  • 7
-3
votes
3 answers

Different outputs while defining local variables

Why do I get the output for i2 as 1 in DevC++ while in other places i get 0? #include int main(void) { int i1,i2; char c1,c2; float f1,f2; long l1,l2; double d1,d2; printf("\n%d %d",i1,i2); printf("\n%c…
-3
votes
1 answer

How to access variable by its name

How can I access variable by its name? a = Hash.new a["test"] = 9 some_method(:a) # => {"test" => 9}
Sato
  • 8,192
  • 17
  • 60
  • 115
-3
votes
1 answer

How to extract multiple numbers from a string and assign to individual variables

Lets say I have the string "first=53 second=65 third=82". How do I assign each value to variables x, y, z? Edit: The words must match as well. With the + signs and exact number of spaces.
rightDrop
  • 61
  • 1
  • 11
-3
votes
1 answer

Error not a statement in java

So I'm just new at java and gui and we have this project to make a java program that will compute for a certain thing with GUI. I'm having this error "Error not a statement in java" can some body help me? And is it possible lessen the space at the…
Dex
  • 19
  • 3
-4
votes
2 answers

Is there an alternative to declaring a variable inside a for loop?

I am trying to count the number of odd values in the elements of the array. Is there a way to perform the below operation without declaring a variable inside the for loop? I am aware that the variable declared inside the loop cannot be accessed…
Kshitiz Sampang
  • 29
  • 1
  • 1
  • 12
-4
votes
1 answer

Why local variables are stored in stack memory for java

I just want to know about the local variables are stored in stack memory
P Phyo
  • 9
1 2 3
86
87