Alan Freedman -- The Computer Language Company - Computer Desktop Encyclopedia
Computer Desktop Encyclopedia
Longest-Running Tech Reference on the Planet

A CDE Definition

You'll love The Computer Desktop Encyclopedia (CDE) for Tech Term of the Day (TTOD)



A structure that holds data within an executable program. Mostly created by and uniquely named by the programmer, variables may store predefined data at the start of the program or be empty containers until a value is placed in them. The values may remain constant or be updated in RAM as the program runs. Variables are used as counters to sum totals and do math as well as to keep track of processes that are repeated within the program. There may be dozens or hundreds of variables defined in a single application.

Using C/C++ as the example language, the statement int counter; defines an integer variable for whole numbers named COUNTER. The statement counter=1; stores a 1 in COUNTER, and counter++; adds 1 to COUNTER. A "char" variable holds character data. A single character variable requires single quotes, but a "string" of characters uses double quotes; for example, mode='A'; and product="abc"; places A in the variable MODE and ABC in PRODUCT. See string, integer and RAM.

Variables Are Control Values
Variables are widely used to repeat a process. In the following for statement, the function DO-SOMETHING is performed five times. At first, x is set to 0. All statements between the left and right curly braces ({ }) are performed. Then, x is incremented by 1 until x is no longer less than 5.

    for (x=0; x<5; x++)




Local and Global Variables
A local variable is one that is referenced only within the subprogram, function or procedure it was defined in. A global variable can be used by the entire program. See environment variable, undefined variable and local variable.

Actual Variable Examples
The following integer variables and character strings were extracted from a program written in C that converts an XML encyclopedia feed to an HTML feed. The =NO is the same as inserting a 0. Variables are often used to keep track of internal modes that are turned on and off while the program is running. YES and NO are the same as 1 and 0 to the compiler.

int ForceOne=NO, ForceAll=NO, NoMoreFiles=NO;
int XMLfileNewer=NO, EndFile=NO;
int TermsWith1Link=0, TermsWith2Links=0;
int TermsWith3Links=0, TermsWithNoLinks=0;
int AFTermCount=0;
int AF_results=0;
int AF_EOF=0;
int hFileAF;
char AFbuff[2000];
char *AFptr;
char HREF1buff[500];
char HREF2buff[500];
char HREF3buff[500];

Personal Use Only

Before/After Your Search Term
VANvariable data printing
vandalvariable declaration
Vanderpoolvariable length field
VANETvariable length record
vanity searchingvariable playback
VAPvariable refresh rate
vapevariable resistor
vapingvariable speed playback
VARvault app

Terms By Topic
Click any of the following categories for a list of fundamental terms.
Computer Words You Gotta KnowSystem design
Job categoriesUnix/Linux
Interesting stuffPersonal computers
InternetIndustrial Automation/Process Control
Communications & networkingAssociations/Standards organizations
HistoryDesktop publishing
ProgrammingHealthcare IT
System design