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;


Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

1 Response

  1. June 17, 2021

    […] our previous article, We looked at the Variables in C-Language. In this article We are going to discuss Escape Sequences in C programming language. We will learn […]

Leave a Reply