Variables
 

Variables are used in programming to transfer information from one part of the program to another as well as being a place to store status information that might be needed by all parts of that program.

A programmer can imagine a variable as being a box into which information can be placed, and the shape of the box (the variables type) determines what kind of information it can store.

Scope
The scope of a variable defines whether it can be accessed and/or modified by a given part of the program. If it can be accessed, it is said to be in scope, otherwise, it is said to be out of scope.

Local variables
are those that are in scope within a specific part of the program (function, procedure, method, or subroutine, depending on the programming language employed).

Passing variables
can be done by value (read-only), and the information can be read by the program part (function, procedure, method, subroutine, etc.) but not modified.

To allow modification, they should be passed by reference. This passes a pointer to the variable, rather than the value, and ensures that the variable is read-write, when in scope.

Global variables
are those that are in scope for the duration of the programs execution. They can be accessed by any part of the program, and are read-write for all statements that access them.

Variable Types
Since data can take a variety of forms, variables need to be defined according to their data type .

In addition, we can define variables as scalars, having one discrete value in a predefined range determined by their data type, or arrays, containing a list of scalar values of a specific dimension.

Finally, there are user defined types (UDTs) and abstract data types,
(ADTs) which allow the programmer to extend the programming language by defining their own data types.

(c) Shilpa Sayura Foundation 2006-2017