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

generating (executable) code dynamically

I have a function that accepts two Strings void setStringValue(String varname,String varValue){ //I am trying to do something crazy and change an extern variables' value here extern String varname; varname = varValue; //And extern…
Nigel Tiany
  • 71
  • 12
-1
votes
1 answer

how to use variable declared in one method in another method

I have wrote a method called "Get_connection" to connect SQL server with my Servlet and i can't use "out.println();" method inside this method even though i passed http servlet Responce as parameters.. Could anyone please explain how to rectify.. …
-1
votes
2 answers

Java: reference to non-finial local variables inside a thread

I am creating some Java codes like the following: new Thread() { @Override public void run() { for(;;) { DataPkg data_pkg = new DataPkg(datapkg_passport, new Data); try{ int len =…
-1
votes
1 answer

Confusion in Scope and Life Time of a local variable in c/c++

My question is that when the lifetime of a local variable is at block level then why the pointer is still printing the value of a local variable even outside the block #include using namespace std; int main(){ int *p; { …
Nadeem Bhati
  • 739
  • 1
  • 8
  • 13
-1
votes
1 answer

Duplicate Local Variable error in a For loop

I'm trying to make a program that finds the sum of all the integers between two numbers, inclusive. I'll paste what I have so far, but I'm getting an error (i is a duplicate local variable?). Thanks public int sum(int num1, int num2){ if (num1…
-1
votes
4 answers

Assigning a local variable whose name is given as a string

Within this itteration: a1=[1,2,3,4,5] a2=[1,2,3,4,5] a1.each_with_index{|a, i| ... = a + a2[i]} I want to assign to different local variables b1, b2, ..., b5, each per iteration to get: b1 # => 2 b2 # => 4 b3 # => 6 b4 # => 8 b5 # => 10 I…
treeseal7
  • 739
  • 8
  • 22
-1
votes
1 answer

Why does this substitution cipher script keep throwing an error?

I'm very new to python so bear with me. I'm putting together a little crypto puzzle and part of it requires a substitution cipher. In this case each letter is replaced with three random letters. Every time I run this code it throws an error when I…
-1
votes
2 answers

Why can't I see method-local variables outside the method?

I'm new to Java and wanted some clarification, I understand that I'm declaring an int variable of x inside the method's parameters but why is it that 'result' can not be resolved to a variable. public class Methods{ public static void…
user3130676
  • 1
  • 1
  • 5
-1
votes
1 answer

why can't I return local variable?

I don't know why c++'s rule says that I can't return local variable? this simple "max" function totally has no problem; int max(int a,int b) { int maxnum; if(a>b)maxnum= a; else maxnum= b; return maxnum; } int main( int argc, char**…
user3094631
  • 425
  • 3
  • 13
-1
votes
1 answer

C - Global vs Local multidimensional array

When I execute this code (gcc compiled): #include int main() { int table[1005][1005]; return 0; } it stops working, but when I change it to: #include int table[1005][1005]; int main() { return 0; } it works…
yat0
  • 967
  • 1
  • 13
  • 29
-1
votes
2 answers

How to dynamically define local variables

I want to loop through an array of one word strings and turn them into instances of a class. Something like this: names_array = ["jack", "james","jim"] names_array.each { |name| name = Person.new } I've tried using eval like (names_array.each {…
Peter
  • 55
  • 3
  • 9
-1
votes
4 answers

Javascript: how to set value for local variable

it is possible to set value for the local variable when you call it ? it is my code var myvar={ F:function(){ var x; return x;} } my problem is when I call the x variable and set value like myvar.F().x="hello"; . then recall it…
Ega
  • 55
  • 19
-1
votes
3 answers

How to change the value of a local variable (python) each time the code loops?

I have to create an ATM style program wherein the code looks something like this: import sys def ATM(): bank = 0 coins = int (input ("Enter coins: ")) bank = coins+bank o = input("would you like to take out 20p? Y or N") if o ==…
oreo666
  • 1
  • 3
-1
votes
1 answer

Are changes made to a global variable, inside a function, reflected globally? Javascript

If I have a global variable, and I change the variable's value inside a function, will the change be reflected outside of the function? e.g. var blaah="blaah"; function myFunction(){ blaah="blaah blaah"; } console.log(blaah); Will the output of…
Ben
  • 2,200
  • 20
  • 30
-1
votes
1 answer

Objective C - How to return local variable in this code?

I have the following code that works. It successfully displays myName in the NSLog ... NSURL *apiString = [NSURL URLWithString:@"http://testapi.com/url"]; [XMLConverter convertXMLURL:apiString completion:^(BOOL success, NSDictionary *dictionary,…