answersLogoWhite

0


Best Answer

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

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

something bad happens... like getting it wrong on your ITT capstone assessment questionnaire...

this answer is awesome! and correct.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Either compilation or run-time error. The results are unpredictable.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the implications of misidentifying a local and global variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the implications of misidentifying a local and global variable?

Your program won't work correctly.


Is a global variable a non-local variable?

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.


What is a local variable and What statements are able to access a local variable?

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.


What is the difference between a static variable a global variable and 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.


How can you declare global and local variable in pseudocode?

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.


How are global variable different from local variable in Visual BASIC?

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.


How do you access global variable from within the main function when the local variable is of the same name?

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.


What are local variables in Visual BASIC?

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.


How do you hide local variables in c and give precedence to global variables inside the function?

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.


Analyze the difference among local module-level and global variables and explain how ActiveX DLLs are created?

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


Which operator is allow to access hidden global variable?

The scope resolution operator, ::, overrides local scope and allows access to objects that are hidden due to global to local scope rules.


What is the difference between global variable and extern variable?

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.