2 answers:
1. You made a variable global; it should have been local.
No biggie. Although deemed 'unprofessional' by most programmers, nothing can really go wrong if you make global variables.
2. You made a local variable instead of a global one.
Big issue. If you define a variable IN a function, then the variable is deleted when the function ends. This means that when you call the function again, that variable will act exactly the same as it did last time. A global variable will keep its value stored until the end of the program, which means it can change during the course of the program.
Suppose you do this:
void printCounter()
{
int i = 1;
cout << i; //this is C++ but this basically prints the value of i onscreen.
i++;
cout << i;
}
This is a local variable.
If you run this twice, you will get the output
1 2 1 2
Suppose you do this:
int i =1;
void printCounter()
{
cout << i; //this is C++ but this basically prints the value of i onscreen.
i++;
cout << i;
i++;
}
Now the value of i is saved, even when the first printCounter function ends.
Your output will be:
1 2 3 4
something bad happens... like getting it wrong on your ITT capstone assessment questionnaire...
this answer is awesome! and correct.
Either compilation or run-time error. The results are unpredictable.
Your program won't work correctly.
True, a variable cannot be both global and local. But if a global and a local variable share the same name, the local one will hide the global.
A local variable is a variable that can only be called on by the module. Where as a global variable can be called upon by any module. Only statements made inside the same module can call on a local variable.
A static variable is a variable allocated in static storage. A local variable is a variable declared inside a function. A global variable is a variable declared outside of any class or function. Note that local variables and global variables can both be allocated in static storage.
A local variable is a variable declared inside a construct, such as a class or function, while a global variable is a variable declared outside of any construct.
A global variable is available for use throughout the program. It is normally declared outside any procedure. A local variable is only available for use in the procedure it was declared in. Most variables are local, but there will be occasions when you want different procedures to be able to use the same variable. This is when you use a global variable.
When you acess a global variable inside main function you must use the same name, because the variable declared as global can be accessed by any function/procedure on the class where it was defined.
A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.A local variable is only available for use in the procedure it was declared in. Most variables are local. Once the procedure ends, the variable is lost, but as the procedure has done its job, that is not a problem. The opposite is a global variable which is declared outside all procedures and is available for use by any of them.
Hi, I would like to answr the question.So, if you want the to give more precedence to global variables with respect to a local one.Just add a pair of curly braces in the local variable and by doing so u can access global variable.
Local Variable A Local variable is a variable whose scope is limited to the Block of the Subroutine defining it. Private Sub Command1_Click Dim a as integer End Sub Module Level Variable A Module Level variable is a variable whose scope is limited to the Form Module defining it. Public Sub Command1_Click Dim a as integer End Sub Global Level Variable A Global Level variable is a variable whose scope can be limited to the entire project defining it. Private Sub Class_Initialize () Dim a As Integer End Sub
The scope resolution operator, ::, overrides local scope and allows access to objects that are hidden due to global to local scope rules.
Global variables are non-local variables. That is, variables that are not defined in a function or class. They are globally accessible to all code in the same translation unit. External variables are global variables that have external linkage; they are accessible across translation units.