Next: Variable Names Up: Constant and Variable Previous: Constant and Variable


In C, a variable must be declared before it can be used. Variables can be declared at the start of any block of code, but most are found at the start of each function. Most local variables are created when the function is called, and are destroyed on return from that function.

A declaration begins with the type, followed by the name of one or more variables. For example,

int high, low, results[20];
Declarations can be spread out, allowing space for an explanatory comment. Variables can also be initialised when they are declared, this is done by adding an equals sign and the required value after the declaration.

int high = 250;     /* Maximum Temperature */
int low = -40;      /* Minimum Temperature */
int results[20];    /* Series of temperature readings */
C provides a wide range of types. The most common are

There are also several variants on these types.

All of the integer types plus the char are called the integral types. float and double are called the real types.
Tue Jan 17 11:40:37 GMT 1995