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
0
votes
5 answers

How to make a variable (truly) local to a procedure or function

ie we have the global declaration, but no local. "Normally" arguments are local, I think, or they certainly behave that way. However if an argument is, say, a list and a method is applied which modifies the list, some surprising (to me) results…
RFlack
  • 436
  • 1
  • 5
  • 19
0
votes
0 answers

Overload operator for Complex Objects

I need to overload operator - for my complex type.I try to use that, but that's not helps. myVector & operator -( myVector & iVect ) { int size = iVect.getSize(); myVector temp( size ); for( int i = 0; i < size; ++i ) temp[ i ]…
0
votes
1 answer

UnboundLocalError variable not recognized

I am getting an error that says: UnboundLocalError: local variable 'words' referenced before assignment but I am unsure on why. The following is my code: def hasher(fname): try: with open(fname, 'r') as f: words =…
user1871869
  • 3,317
  • 13
  • 56
  • 106
0
votes
1 answer

Redeclaration of variable, in a switch statement in C

I'm using a switch statement that basically looks like this: switch (command): case '+': int key; scanf("%i", &key); //do stuff break; case '-': int key; scanf("%i", &key); //do stuff break; .... It appears I'm not allowed…
user339946
  • 5,961
  • 9
  • 52
  • 97
0
votes
1 answer

Retrieve a float from database and adding to local variable

i have a problem with setting the value of the local variable, after i have retrieved the float value from my database. It says it is not the same type, samplerate and the value from (float)rdr["samplerate_hz"]; My code i like this. public…
Emil
  • 3
  • 2
0
votes
4 answers

Why does Python print this?

Can someone explain why this Python code: def function(string, i, j): if (i < j): i = i+1 string1 = string[i:j] return string1 else: return string # main string = "four score and seven years ago" i = 5 j =…
user2989980
0
votes
2 answers

synchronized on local variable, better than synchronized methods?

I wrote a wrapper around database queries and need to access it from different threads. Therefore my application creates exactly one instance of that helper class and returns it through a getter. DbConnection dbc =…
0
votes
2 answers

how to call php variables outside php tags

i want to call $query somewhere inside the html and this returns undefined. Even after declaring the variable as GLOBAL i still get that error. The Full PHP
Relm
  • 7,923
  • 18
  • 66
  • 113
0
votes
1 answer

Should I keep Application subclass object as a member or local variable?

I was wondering, I am using Application subclass to access some global data inside Activities. And I was wondering what would be better in terms off performance and memory. Is it better to assign application object to field variable in onCreate and…
urSus
  • 12,492
  • 12
  • 69
  • 89
0
votes
6 answers

i and j not being initialized. But I already wrote int i and int j. What is wrong

When I try to compile it, Eclipse says that i and j has not been initialized. What am I doing wrong? The question is about creating a circle. public class Question2 { public static void main(String[] args) { int x = 14; int y…
0
votes
5 answers

Dr Java error on code

It is saying that my local variable newaccbalance may not have been initialized. I know I declared it as a double. Help please import java.util.*; public class Pg244Problem12 { public static void main(String[] args) { int accnum,…
0
votes
2 answers

C# - Use of unassigned local variable

I'm making an account system for Unity and this is my script, I get the error on lines 132, 134, 136 before the TextField and PasswordFields. I can't tell what's wrong with it. Any help would be greatly appreciated. using UnityEngine; using…
0
votes
3 answers

How can $(this) be available globally

In JQuery, it seems that $(this) only works locally. give a quick example: $(".someClass .type1").click(function(){ $(".someClass .type1").html(""); $(this).html("
the_summer_bee
  • 483
  • 4
  • 10
  • 23
0
votes
3 answers

Methods don't know about outside variables?

Say I'm writing a division algorithm script: def current_trace puts "Counter: #{counter}; r: #{r}; q: #{q}" end r = a q = 0 counter = 0 while r >= d current_trace r = r - d q = q + 1 counter += 1 end current_trace I expected that…
Jackson
  • 9,188
  • 6
  • 52
  • 77
0
votes
1 answer

Stacksmashing without even accessing any data

On my machine, the following code apparently produces stacksmashing: #include #include void function2(int* data); void function1(); void function2(int* data) { printf("grps "); printf(" "); printf(" one more…
MrBrody
  • 301
  • 2
  • 13