Friday, September 21, 2018

Variables

Variable is a container used for temporary storage of data.

According to wikipedia,

In computer programming, a variable or scalar is a storage location (identified by a memory address).

Why are variables required?

This can be understood by an example:

If there is a number say 1233344588777669900 which has to be used in multiple calculations,then one way would be to key in the number each time it is required.
The second method would be to use M+ key available in calculator.The momemt we press M+ key,the specified number gets stored in the calculator's memory and can be recalled whenever required by pressing the MR key.
The same appliesto data used in a program.The data,which is repeatedly used has to be temporarily stored in a variable so that it can be accessed when required.

How much memory does variable require?

The amount of memory required to store an integer(number eg.6) is 2 bytes and character eg 'a' is 1 byte. 

Memory allocation is done by programming language not by user.

No comments:

Post a Comment