FAQ Database Discussion Community


How to dynamically define local variables [duplicate]

ruby,metaprogramming,local-variables
This question already has an answer here: How to dynamically create a local variable? 1 answer 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 }...

why can't I return local variable?

function,opencv,return,local-variables
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** argv ) { cout<<max(10,30); system("PAUSE"); return 0; } but,...

Identify the arguments, parameters, local variables and global variables used in the following code?

javascript,parameters,arguments,global-variables,local-variables
The code is: var x = 32; var y = 44; var radius = 5; var centerX = 0; var centerY = 0; var width = 600; var height = 400; function setup(width, height) { centerX = width/2; centerY = height/2; } function computeDistance(x1, y1, x2, y2) { var dx...

java - How to retrieve anything inside method

java,methods,constructor,local-variables,bcel
From what i know, java cannot retrieve anything inside method. so i using option -g or -g:vars in javac. for e.g : class Test { int a=0; void method(boolean boo){ String b; try { new Thread().sleep(1000); } catch(InterruptedException e){} JOptionPane.showMessageDialog(null,"test"); BufferedImage image=ImageIO.read(new File("C:\\file.png")); } } So, i use BCEL to...

Why a variable defined global is undefined? [duplicate]

javascript,global-variables,local-variables,hoisting
This question already has an answer here: 'Hoisted' JavaScript Variables 4 answers Hi guys here I have a simple function and a global variable. My question is why myname = "glabol" is undefined and not the string "global" var myname = "global"; // global variable function func() { alert(myname);...

Get value from string representing local variable [duplicate]

ruby,local-variables
This question already has an answer here: Is there a 'variable_get' method? If not, how can I create my own? 2 answers I have a local variable name as a string, and need to get its value. variable = 22 "variable".to_variable? How can I get the value 22 form...

How could I use these local variables for object position in my main function?

c++,vector,global-variables,computer-vision,local-variables
I'm using some computer vision code in c++ that tracks an object after you draw a bounding box around it, and it can track multiple objects with multiple bounding boxes. In one of the header files there is a function that processes the frame and defines the objects center pixel...

What does “local variables at the outermost scope of the function may not use the same name as any parameter” mean?

c++,parameters,scope,local-variables
I have been reading the C++ primer 5th edition. In the third paragraph of Function Parameter List of Chapter 6.1 . It writes "Moreover, local variables at the outermost scope of the function may not use the same name as any parameter". What does it mean? I am not native...

Local variables on stack

c,stack,local-variables
To understand the stack frame concept, I wrote a little program for my own. First I will show you the code, a little sketch about it and then I will present my question: So, the program: int check_pw(char *password){ int valid = 0; char buffer[10]; strcpy(buffer, password); if(strcmp(buffer, "a") ==...

C++ Same name local variables keeping values between loops [closed]

c++,loops,for-loop,local-variables
I have the following 2 loops in my C++ code: for (int hcount = 0; hcount < height; hcount++) { for (count = 0; count < width; count++) { cout << character; } cout << endl; } cout << endl; for (int hcount = 0; hcount < height; hcount++); {...

Java Garbage collection against Local and Global variable with Thread Safe

java,garbage-collection,thread-safety,global-variables,local-variables
Which of the below snip of code is more Garbage Collection efficient in terms of TIME Class Test{...} Local Variable private void function(){ Test test = new Test(); .... } Global Variable Test test = null; private void function(){ if(test == null){ test = new Test(); } } Let assume...

Global variable returned as undefined when it is again declared locally in a block and referred before the declaration in the block. [duplicate]

javascript,global-variables,local-variables
This question already has an answer here: Why does local variable kill my global variable? 6 answers var a = 10; function example(){ alert(a); var a = 5; } example(); This code alerts undefined. My question is why variable a is alerting "undefined" instead of returning global variable's value....

Python helper function scope

python,function,scope,local-variables
So, I have a whole bunch of things doing basically the same thing with only a slight change in input. Perfect candidate to be function'd out and called each time with different parameters, right? Apparently, python thinks I'm wrong. So, here's a boiled-down version of my problem def main(): x...

C - Global vs Local multidimensional array

c,multidimensional-array,global-variables,local-variables
When I execute this code (gcc compiled): #include <stdio.h> int main() { int table[1005][1005]; return 0; } it stops working, but when I change it to: #include <stdio.h> int table[1005][1005]; int main() { return 0; } it works just fine.. Why is this concretely happening? Does global variables get more...