Variable:
Variable is an entity whose value can vary (i.e. change) during execution of a program.
int a = 20;

- #include<stdio.h>
- main()
- {
- printf("********* Example Variable *********\n");
- int i, j;
- i = 10; j = 20;
- printf("\n value of i=%d & j=%d \n",i, j);
- // change the value of variable
- printf("\n change value of variable ");
- i = 50;
- printf("\n After changing value of variable i is : %d \t", i);
- getch();
- }

Real life example of variable
- Everyone has a saving / current bank account. From this account you can withdraw money from ATM or deposit money by visiting the bank.


Constant:
Constant is an entity whose value cannot be changed throughout the execution of program.
const int j = 50;
- #include<stdio.h>
- main()
- {
- printf("********* Example Constant *********\n");
- const int i = 100;
- printf("\n value of constant i= %d \n",i);
- i = 50;
- printf("\n%d \t", i);
- getch();
- }
- #include<stdio.h>
- main()
- {
- printf("********* Example Constant *********\n");
- const int i ;
- printf("\n value of constant i= %d \n",i);
- //i = 50;
- printf("\n%d \t", i);
- getch();
- }

Real life example of constant
- Now suppose we want to create a fixed deposit in bank. This is done to keep a particular amount locked for some specific period.

Summary:
This article will help fresher candidates to understand Variables & Constants in C with Real Life Example.


Rupesh KahanePosted Dec 30, 2015, 7:24 AM EST
thanks Harshad Pansuriya
Harshad PansuriyaPosted Nov 13, 2015, 6:00 PM EST
Nice one
Rupesh KahanePosted Nov 13, 2015, 4:51 PM EST
thanks to Santhakumar Munuswamy & Banketeshvar Narayan also
Banketeshvar NarayanPosted Nov 13, 2015, 11:49 AM EST
Nice Article
Santhakumar MunuswamyPosted Nov 13, 2015, 5:11 AM EST
Good one
Rupesh KahanePosted Nov 13, 2015, 3:56 AM EST
Thanks Debasis Saha
Debasis SahaTOP 100Posted Nov 13, 2015, 3:44 AM EST
Good Share
Rupesh KahanePosted Nov 12, 2015, 6:56 PM EST
thanks to all Sibeesh Venu, Raja T & Anish Ansari
Anish AnsariPosted Nov 12, 2015, 3:37 AM EST
NIce
Raja TPosted Nov 11, 2015, 11:16 PM EST
Good one, Thanks for sharing ..
Sibeesh VenuTOP 100Posted Nov 11, 2015, 11:03 PM EST
Nice Share