Programming Concepts - Variables

Variables can are found in all programming languages. These are designed to be used to store values which can then be manipulated by the program. In a very basic way, variables can be thought of as containers of differing types. The differentiation comes with the fact that each variable has to be associated with a data type, i.e. Integer, Character, String etc.

Variables are used in programming for various reasons. They are commonly used to capture data from the user and also to store temporary values. For example, when the program requests a user to enter their name, the resulting input is stored in a variable which could be named “username”. This variable can then be accessed by other parts of the code for its data whenever required. At the end of the program or on its next run it will not hold the previous data that was entered as it will have new data entered by another user (hence the term variable).

In most languages, variables can be defined as Global or Local. Global variables can be called up anywhere in the program, so they can be defined only once. To continue with the previous example, if “username” was a global variable, another variable with the same name cannot be defined. However, local variables can be defined with the same name in different parts of the program within Procedures, Functions etc. For example, a variable named “temp” can exist in many procedures if it is only defined locally i.e. within that procedure.

Variables can be defined anywhere in the program except in the case of a Strongly Typed programming language. In this instance, the variable has to be defined before it is used.

This entry was posted on Sunday, February 21st, 2010 at 10:55 am and is filed under Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply