In c programming language, “Variables’ are the named memory locations where user can store different types of values of same datatype during the execution of program. That means, variable is a particular name given to a memory location in which users can store different values of same datatype.
In short, we can define the variable as this is an storage container, which is used to hold different values of same datatype during the execution of C program.
Explanation of datatype in brief are:-
àIn c programming language, every
variable must be declared in the memory declaration section before it is used
for the execution of program. Every variable must have a datatype that
determines the range and type of values has to be stored and size of the memory
has also to be allocated.
A variable name may contain letters, digits and underscore symbol. There are some rules to specify a variable name given below:-
- Variable name must not start with digit.
- Keywords should not be used as variable names.( can not be used as variable names.)
- Any special symbols are not allowed to declare ‘Variable name’ 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 give instructions to the compiler that allocate 2 bytes of memory with the name number and allows only integer values at that memory location.