Why are Variables and Constants used in Programming ?
Notes:
Why are Variables and Constants used in Programming ?
C Variables and Constants:
While developing any software application, we will be dealing with different types of data & data values.
Ex:
If we are building a banking application then we need to maintain different types of data & data values:
accountNumber=10; // accountNumber is integer type of data
rateOfInterest=13.5; // rateOfInterest is real type of data
accountHasLoan=true; // accountHasLoan is Boolean type of data
Ex:
If we are building a game, then we need to keep track of different types of data & data values:
playerScore= 10; // playerScore is integer type of data
worldGravity =9.8; // worldGravity is real type of data
isGameOver=false; // isGameOver is Boolean type of data
In order to store and process all such types of data & data values computer uses its memory (RAM).
In order to allocate a chunk of memory in the RAM and access it within a C program; we create a variable or constant.
Note:
- To store and process different types of data & data values; variables & constants are created.
- To allocate memory locations in the memory and access them within a C program; variables & constants are created.