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
10 answers

local variable and instance variable. Java

So I was testing some code and here they are: public class Phone { String phoneNumber = "1234"; void setNumber(){ String phoneNumber; phoneNumber = "4321"; } } public class TestPhone { public static void…
OPK
  • 4,120
  • 6
  • 36
  • 66
-1
votes
2 answers

SQL Server : Select Local Variable After Some Process

CREATE PROCEDURE dbo.test2 AS BEGIN DECLARE @status as int DECLARE @error as int SET @status = 1 SET @Error = @@ERROR UPDATE dbo.BView SET bview='dar' WHERE pt='foo' IF @Error > 0 print…
-1
votes
1 answer

Where do tmp files go after Bash finishes with a "local" variable?

I really screwed myself over recently. I have a function which will swap the contents of two files: function swap() { local TMPFILE=tmp.$$ mv "$1" "$TMPFILE" mv "$2" "$1" mv "$TMPFILE""$2" } ^ As you can see…
nargetdev
  • 23
  • 1
  • 5
-1
votes
2 answers

Local variable behaviour with list, string, and stringbuffer

I am a newbee. I have read that the scope of local variables will be within a block (correct me if I am wrong). Here, the main method's local variables (the lists li and li1, and the StringBuffer y) are behaving like instance variables, and the…
LMK
  • 2,882
  • 5
  • 28
  • 52
-1
votes
3 answers

Memory allocated for global variable and local variable in c : is it different

(GLOBAL DECLARATION OF CHAR ARRAY) #include char name[10]; /* though allocated memory is 10 bytes still it accepts more then 10 chars*/ void main() { printf("\n ENter name :\t"); scanf("%s",name); } Second case:(LOCAL…
alpha9eek
  • 1,439
  • 3
  • 11
  • 10
-1
votes
1 answer

Why is a global variable called when there is a local variable?

Give the EXACT output generated by the Java code shown below. int x=1, y=-5, z=4; // global variables int vals[] = {-6,2,-4,-8 ,-2,-3}; // global variables public void setValues() { char y = 'R'; z=10; System.out.println("l1: "+x+" "+y+"…
-1
votes
4 answers

Value of Local variable in of one function used in another function (c programming)

#include void bar() { int a=4; } void foo() { int a; printf("%d",a); } int main() { bar(); foo(); } I'm sure that the above program gives the output as some junk value(Thats what happenes when i compile and run). But I read in an…
nupadhyaya
  • 1,909
  • 1
  • 14
  • 14
-1
votes
4 answers

Making my code more polymorphic

So I have this code: https://gist.github.com/anonymous/0760d154f81064bf8493 (Sorry it's 5 classes so i couldn't put it here) And I think I have implemented polymorphism in it to a decent extent. But is there anything I else I could do to make it…
Strobe_
  • 495
  • 1
  • 13
  • 34
-1
votes
1 answer

android java code error

I am creating a keyboard but there is some error in local variable usage. private void updateCandidateText(){ try{ ExtractedText r= getCurrentInputConnection().getExtractedText(new…
-1
votes
2 answers

Retrieving local variables in PHP at runtime?

If I do print_r in $GLOBALS I have all globals vars. But I need something like this: function foo() { $a = 1; $b = 2; for($i = 0; $i < 10; $i++); } print_r(find_variables_in_function('foo')); // results: array(a => 1, b => 2, i =>…
Ragen Dazs
  • 2,115
  • 3
  • 28
  • 56
-1
votes
3 answers

memory storage for constant data in c++

As mentioned in the C++ Complete Reference, constant data are stored in ROM. But Local variables are stored inside the stack, which is in RAM. So if we declare local constant data, where is it stored? RAM or ROM?
Viku
  • 2,845
  • 4
  • 35
  • 63
-1
votes
2 answers

ConcurrentModificationException with global variables but not local with local variables

In the following function I have declared local variables allPeopel and itr(they are overriding global variables). If I comment out the local variables (between the Astrixes below), then a ConcurrentModificationError is thrown. However, if I use…
-1
votes
3 answers

Assigning nil to a member variable which is passed to a method

I'd like to assign nil to an object, which is an ivar, passed in as a parameter to a method, something like this. - (int)trashObjectPassedIn:(Banana* banana) { banana = nil; return 42; } Of course, if I call it like this: [self…
Josh Paradroid
  • 1,172
  • 18
  • 45
-1
votes
2 answers

jQuery: how to access outside variable?

I am in a situation that needs be solve with this way; need convert a local variable to a global variable. There is an example returning image's real width and height which i found these method from this answer.. Need to convert local varialbes…
-1
votes
2 answers

C local variable address return warning

I have this function in C: static Node* newNode(void* e){ Node n={e,NULL,NULL}; return &n; } And while compiling I get the following warning that I would like to understand why it happens: warning: function returns address of local variable…
Leonardo Marques
  • 3,721
  • 7
  • 36
  • 50