Difference Between Similar Terms and Objects

Difference Between Local and Global Variables

Local vs Global Variables

Global variables can be used anywhere in a computer program. This means that global variables can be used in many functions. This global variable can be used in various user defined header files as well as java packages. The global variables can also be changed programmatically.

When talking about local variables, it is just a local computer programming or is local to a function. Local variables cannot be used beyond the particular function. The lifetime or scope of a local variable is just within a procedure or a block whereas the scope of a global variable is throughout the program.

Local variables are just used in the function where they have been declared. Moreover, the local variable only remains lifetime as long as the sub or function is in vogue. Once the program comes to an end, the local variable gets erased from the memory.

While modifications in a global variable can be made from anywhere, it cannot be done with local variables. If the global variable is present in protected memory, modifications cannot be made in a global variable.

There are many advantages with local variables and global variables. An added advantage of the local variable is that it makes it easier to debug and maintain the applications. But in the case of global variables, one cannot be sure in which function it will be modified or when the variable values will be modified. On the other hand, in a local variable, there is nothing to trace. In the case of local variables, there is an advantage that it comes with fewer side effects when compared to global variables.

Summary:

1.Global variables can be used anywhere in a computer program. When talking about local variables, it is just a local computer programming or is local to a function.
2.This global variable can be used in various user defined header files as well as java packages. The global variables can also be changed programmatically.
3.The lifetime or scope of a local variable is just within a procedure or a block whereas the scope of a global variable is throughout the program.
4.While modifications in a global variable can be made from anywhere, it cannot be done with local variables.

5. An added advantage of the local variable is that it makes it easier to debug and maintain the applications. But in the case of global variables, one cannot be sure in which function it will be modified or when the variable values will be modified. On the other hand, in a local variable, there is nothing to trace.


Search DifferenceBetween.net :

Custom Search



Help us improve. Rate this post! 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...


Email This Post Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.



See more about :

1 Comment

  1. thanks for explaining it, I was very confuse about that.

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Articles on DifferenceBetween.net are general information, and are not intended to substitute for professional advice. The information is "AS IS", "WITH ALL FAULTS". User assumes all risk of use, damage, or injury. You agree that we have no liability for any damages.


Protected by Copyscape Plagiarism Finder