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

How to debug "C++ Function does not take 0 arguments" error?

In my C++ programming class I am tasked to create a payroll recorder for 5 employees. One of the requirement is no global variables, therefore I think this requires me to declare variables locally within each individual functions and pass them…
-2
votes
4 answers

How do I make my variables accessible to other classes?

The variables bounds, width and height are at present local variables. I cannot access them from other classes or even access them from another method. How can I make these variables available to the whole instance? I have tried placing them within…
Declan McKenna
  • 4,321
  • 6
  • 54
  • 72
-2
votes
2 answers

Function that returns a user input string

I am trying to write a function that allows a user to input a name and then return the string back as a variable which I can use in my program. However, every time I've attempted this it seems I've tried to return a local variable or something. I…
iyen
  • 1
-2
votes
1 answer

Variable in for loop is giving a message that "The value of the local variable i is not used"

I wrote a for loop that is supposed to determine if there is user input. If there is, it sets the 6 elements of int[] valueArr to the input, a vararg int[] statValue. If there is no input, it sets all elements equal to -1. if (statValue.length == 6)…
-2
votes
1 answer

Function isn't working with a gobal variable. Should it be expected?

As title says, I can't have the variable "countDash" being used on my function if it's globaly, only local. Should it be like this? What am I missing something? Thanks in advance. //count let countEl = document.getElementById("count-el"); let saveEl…
-2
votes
1 answer

initialize only once non static local variable

void foo() { static int x{0}; int y{0}; // this one // dosomething like ++y foo(); } Is it possible to have variable 'y' initialized only once(when foo called first time, not in each call) but separate independent local copy…
bni
  • 47
  • 4
-2
votes
1 answer

what is the use of static variable in Opengl?

Please attention on my code....... #include #include #include #include static GLfloat spin = 0.0; // Does it use as global variable?? void display(void) { glClear(GL_COLOR_BUFFER_BIT); …
Imdadul Haque
  • 1,635
  • 5
  • 23
  • 44
-2
votes
1 answer

How do I change the variable value in the inner class

I am making a minesweeper game. I want to reduce the number of flags in the inner class but I get this error ."local variables referenced from an inner class must be final or effectively final java".How can I solve this problem ?
Burak
  • 37
  • 4
-2
votes
1 answer

How to access the variables of a function inside main?

I have a program that uses 3 separate files, a header file for function declarations, a cpp file for the definitions, and a main driver file to call the functions. For my function definitions, I have variables being created inside these functions…
user12963789
-2
votes
2 answers

I need to change the variable value after the onClick

"cousin2" should show up as 79,273,859 in the console, because that is what that value equals. But I do now know to how to change the the value after a click function. Other sources said that establishing var cousin2 as a global variable should do…
-2
votes
1 answer

i've a local variable unused in a function that made a matrix

I've a local variable that's not used in a function. This function does a matrix and returns that matrix empty. I've tried to use 'i' variable using an "if i is None: pass" but the issue continue. def create_matrix(rows, columns): matrix =…
-2
votes
2 answers

Why is there no compile time error for not initializing local variable if a local variable is declared like this int a=10,b=3,m;?

I am trying to execute the below code: public class HelloWorld{ public static void main(String []args){ int a=10,b=3,m; System.out.println("Hello World "+a+" " + b); } } I was expecting a compilation error for not…
Alex
  • 33
  • 1
  • 6
-2
votes
2 answers

How do i call on a local variable from another method?

I want to shorten my method, but when doing so some of my variables don't work. Should I do something with the parameters? My user at the bottom auction.makeBid(user, value); is the one that doesn't work. This is my new method to shorten out the…
Elie
  • 35
  • 1
  • 5
-2
votes
1 answer

Why some of the local variables are not listed in the corresponding stack frame when inspected using GDB?

I have a piece of code in C as shown below- In a .c file- 1 custom_data_type2 myFunction1(custom_data_type1 a, custom_data_type2 b) 2 { 3 int c=foo(); 4 custom_data_type3 t; 5 check_for_ir_path(); 6 ... 7 …
Darshan L
  • 824
  • 8
  • 30
-2
votes
1 answer

Local variable initialized in a condition not recognized?

I am learning c++ and I came across a really odd phenomenon in a program. I haven't seen any documentation on this problem. Why is that when I initialize a variable inside of a conditional statement it isn't recognized outside of it? Is the variable…
Evan Gertis
  • 1,796
  • 2
  • 25
  • 59