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

Is it possible to use python.locals() with numba?

I'm working on a python function that dynamically creates and uses variables. When i try to speed it up with numba I get this error message: 'numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) Untyped global…
Talleros
  • 31
  • 3
-1
votes
1 answer

What assembly instruction corresponds to a c language local variable assignment like this?

I'm studying computer architecture and I was thinking about what assembly instruction corresponds to this simple assignment : int main () { int local_test = 10; } Considering that the STORE instruction store something from a register to RAM…
Kode1000
  • 111
  • 3
-1
votes
2 answers

Python Multiprocessing: Variable only changes inside the function even though there is a global statement

I am trying to change a variable inside a function and access the changed one inside another function but the first function won't change the variable globally. what i want my code to do: when i press the "startKey" it should turn on and start…
-1
votes
2 answers

How to stop variables becoming local?

I'm trying to create a function to verify if a move in a game is legal. At the top of my code, I declared the variable Valid. p1 = [1,1] p2 = [1,1] turn = 1 move = 0 Valid = False and later on, I call the function check_swap() and right now, I am…
Jaxon y
  • 17
  • 4
-1
votes
1 answer

Assigning variables in a function

In the code below, I can see that the variables end_line and internal_line are assigned to their characters but then below that in the for loop, another variable called end_line is being assigned to the previous end_line. How? def draw_grid(width,…
-1
votes
1 answer

Is this problem about local,and global variable? I don't know what this doesn't work.(basic python)

This code doesn't work. error says: UnboundLocalError: local variable 'on' referenced before assignment arr = [] for i in range(4): arr.append([0 for t in range(4)]) on=1 num_r = 0 def go_r(d): for i in range(d): …
-1
votes
1 answer

How to make a variable that is inside a method to be recognized outside the method on Android?

Sorry, but showing through images is much better, okay? The explanation follows below: But if you declare the entire variable as a global variable, the following error occurs: Please, what to do so that the variable value inside the blue…
-1
votes
1 answer

How to remove variable from animation code

I am trying to remove this namespaced-scoped variable from the code. How would I be able to do that? Is this able to be done? Local Variable: let currentPlayButton = {}; https://jsfiddle.net/hxar8w1g/ const manageCover = (function makeManageCover()…
user17382064
-1
votes
1 answer

local variable and dynamic memory allocation in c

Hello I am learning basic of c programming and having a little difficulty understanding the behavior of these codes. this is the first one: #include #include int* foo(int start) { int arr[3]; arr[0] = start; arr[1] =…
-1
votes
1 answer

Change arrow function to use var globally

I'm using findNearest to calculate my distance to an array of points (and it returns the closest one) and then I'm calculating the distance to that point. It works but the way I did it does not allow me to use the "found" var globally, only inside…
Caquibf
  • 57
  • 7
-1
votes
4 answers

C - Local variables have the same address and value

I have the following C code: void testA() { int x = 56; printf("Address of x = 0x%x - Value of x = %d\n",&x,x); } void testB() { int y; printf("Address of y = 0x%x - Value of y = %d\n",&y,y); } int main() { testA(); …
-1
votes
2 answers

Are uninitialized local variables in C static by default?

I recently learnt about the static variables, that they retain their values in between various function calls. Then I wrote some code to test it, then hopefully it worked perfect. But then I accidentally removed the static keyword at the beginning…
-1
votes
2 answers

Why aren't local variables garbage collected when referenced in a returned lambda function?

I came across some code that confused me a little and I'd like to know what's going on behind the scenes to make this possible. The code in question was a unit test using the FakeItEasy library. ReturnsLazily() and Invokes() methods were being used,…
RealR55
  • 1
  • 1
-1
votes
3 answers

dotnet C# - Why doesn't the GC free memory?

I would like to ask for clarification on how .net Garbage Collector works in this case. I have a static function in which I allocate the byte array over and over again. I am inserting byte array reference into the list. The reference to the byte…
-1
votes
1 answer

User enter a date string ('year' or 'month') and it applies to date.userinputdate

I have term = input("Enter a variable name") #choose the term (i.e.,day,week,month) and in my code there is a section as below date.term I like users can input 'month' or 'year' and the code can function as date.month or date.year How can I do…