Variables and Data Types

Variables are a way of reserving memory to hold some data and assign names to them so that we don’t have to remember the numbers like 316976 and instead we can use the memory location by simply referring to the variable name. Every variable is mapped to a unique memory address. However, this is not enough. A variable can contain different types of data and each type may have different space requirement. we also specify the data type of a variable which signifies the type of data it contains and the space it requires to hold it. Having a variety of data types at the disposal of programmer allows him to make appropriate data type selection as per the nature of computation and type of machine. In addition, the operations legitimate for one type of data may be invalid for some other type. Having specified the data type of a variable allows the compiler to make compile time type checking in order to avoid run time failures.