Variables in C language | Declaration of Variables | variable Declaration Rules and Initialization of Variables

Spread the love

Variables :

Variable is a Name of Memory location it is used to store the value.

Variable name is saying value of variable varies during the Execution of program. it can capable of change it’s value that means it can take different values but one at a time. 
Variable is for storing data but which kind of data to store ?  answer is Datatype of variable will decides which type of data it is going to take.the rules for naming the variables are same as the Rules for Naming a Identifier.

Declaration of Variable :

  • Variable must be declared before going to use in program.
  • Declaration of variable specify the name and Datatype.
  • Variable are declared at the starting of program that means after opening opening Brace ‘{‘ ( This is not Mandatory but Recommended ).
  • Variable name should not a Operator, separator and Keyword and Constant .

Syntax for variable Declaration :

                       datatype  variablename;

In variable declaration at least one space is needed between datatype and variable name.
for example :  int n; (Valid Declaration).
                         intn;  (Invalid Declaration – at least one space is needed).
When we are declaring multiple variables of same datatype there should be separated by comma ( , ).

Few Examples for variable Declaration :

int M;
char ch;
float percentage;

For declaring more than one variable 


int i,j,k,result;
float add,sum,mul,div;

how variables are declaring and how they are using in programs to perform operations  ?
Just see this program you will get clarity. Program to Perform Arithmetic Operations

Initialization of Variables :


We are just discussed about variable declaration but we are not specified any value to our Variables that means those are contains Garbage Values ( Undefined values compiler automatically assigns on value for each variable while declaration). So how can we give our values to variables answer is Assigning Values. here is a example for it.

int n;    (Variable Declaration ).
n=10;   (Assigning Values ).

if we want to assign some initial value to the variable during the declaration it is called Variable Initialization some thing like this

int n = 10; (Variable is Initialized ).
let’s see few more declarations..
char ch=’M’;
float percentage=78.3;


Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply