Constants & Variables

2 Variables


An entity that may vary during program execution is called a variable. Variables names are names given to locations in memory. A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive. Based on the basic types explained in previous chapter, there will be the following basic variable types:




Typically a single octet (one byte). This is an integer type.


The most natural size of integer for the machine.


A single-precision floating point value.


A double-precision floating point value.


Represents the absence of type.

A variable definition means to tell the compiler where and how much to create the storage for the variable.

For ex: if we write x=3. Here 3 is stored in a memory location and a name X is given to it. X is a variable.

Rules for constructing variable names

1) A Variable name consists of any combination of alphabets, digits and underscores. Some compiler allows variable names whole length could be up to 247 characters. Still it would be safer to stick to the rule of 31 characters. Please avoid creating long variable name as it adds to your typing effort.
2) The first character of the variable name must either be alphabet or underscore. It should not start with the digit.
3) No commas and blanks are allowed in the variable name.
4) No special symbols other than underscore are allowed in the variable name.