Declaration & Initialization of C Variables

C variables are names used for storing a data value to locations in memory. The value stored in the c variables may be changed during program execution.

Declaration of Variable

Declaration of variable in c can be done using following syntax:

data_type variable_name;


data_type variable1, variable2,…,variablen;

where data_type is any valid c data type and variable_name is any valid identifier.

For example,

 int a;
 float variable;
 float a, b;

Initialization of Variable

C variables declared can be initialized with the help of assignment operator ‘=’.


data_type variable_name=constant/literal/expression;




int a=10;
int a=b+c;

Multiple variables can be initialized in a single statement by single value, for example,


NOTE: C variables must be declared before they are used in the c program. Also, since c is a case sensitive programming language, therefore the c variables, abc, Abc and ABC are all different.

Constant and Volatile Variables

Constant Variables

C variables having same or unchanged value during the execution of a program are called constant variables. A variable can be declared as constant using keyword const.

For example,

const int a=10;

Now, if we try to change its value, then it is invalid.

Volatile Variables

Those variables that can be changed at any time by some external sources from outside or same program are called volatile variables.

Any variable in c can be declared as volatile using keyword volatile.


volatile data_type variable_name;

NOTE: If the value of a variable in the current program is to be maintained constant and desired not to be changed by any other external operation, then the variable declaration will be volatile const d=10;