Variables



Variables in c programming language are the named memory locations where user can store different values of same datatype during the program execution. That means, variable is a name given to a memory location in which we can store different values of sasme datatype. In other words a variable can be defined as a storage container to hold values of same datatype during the program execution. The formal definition of datatype is as follows...

Variable is a name given to a memory location where we can store defferent values of same datatype during the program execution.

Every variable in c programming language must be declared in the declaration section before it is used. Every variable must have a datatype that determines the range and type of values to be stored and size of the memory to be allocated.

A variable name may contain letters, digits and underscore symbol. The following are the rules to specify a variable name...

  1. Variable name should not start with digit.
  2. Keywords should not be used as variable names.
  3. Variable name should not contain any special symbols except underscore(_).
  4. Variable name can be of any length but compiler considers only the first 31 characters of the variable name.

Declaration of Variable

Declaration of a variable tells to the compiler to allocate required amount of memory with specified variable name and allows only specified datatype values into that memory location. In C programming language, the declaration can be performed either before the function as global variables or inside any block or function. But it must be at the begining of block or function.

        Declaration Syntax:

datatype variableName;

        Example

                int number;

The above declaration tells to the compiler that allocate 2 bytes of memory with the name number and allows only integer values into that memory location.