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 variable1, variable2,…,variablen;
where data_type is any valid c data type and variable_name is any valid identifier.
int a; float variable; float a, b;
Initialization of Variable
C variables declared can be initialized with the help of assignment operator ‘=’.
int a=10; int a=b+c; a=10; 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
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.
const int a=10;
Now, if we try to change its value, then it is invalid.
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;