Variables in a c programming language are the named memory locations where the user can store different values of the same datatype during the program execution. That means a variable is a name given to a memory location in which we can store different values of the same datatype. In other words, a variable can be defined as a storage container to hold values of the same datatype during the program execution. The formal definition of a datatype is as follows...
Variable is a name given to a memory location where we can store different values of the 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 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...
- Variable name should not start with digit.
- Keywords should not be used as variable names.
- Variable name should not contain any special symbols except underscore(_).
- 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.
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.