Both variables and the constants may have different types of values. In C language, different forms of data are categorized into a few abstract data types. For example, suppose you are asked to keep the record of the number of passengers in a bus. A variable say N, which is used to denote this number, will have value in whole numbers because the number of passengers cannot be a fractional number. Similarly, for number of students in a class, number of apples in a basket, number of pages in a book, or number of houses in a colony, etc., the values must be in whole numbers. Whole numbers form a category called integers. In C language, this type is coded as int, a short form for integer.
Numbers with a decimal point such as 2.4 or 3.14159 form another category or type, which when declared use float or double before their names. A float refers to a decimal floating point number with single precision (7 significant digits after the decimal point), whereas double is used for numbers with double precision (up to 15 digits after decimal point).
If a variable stands for names of students or for names of cities or names of rivers, etc., its values would be strings of characters such as “John”, “Delhi”, or “Ganga”.
An object of a given data type is stored in a section of memory having a discreet size. Objects of different data types require different amounts of memory. Therefore, it is necessary to specify the type of data that a variable will be having so that the compiler allocates appropriate memory size and address for storing its value. Following table shows the size and range of the basic data types.
Sizes and Ranges of Data Types :
Furthermore, there are other types such as void. The void is in fact devoid of any type mentioned above; void cannot be used with any data. It is mainly used with functions that do not return any data and pointers. Void is also called incomplete type. Two data types, the Boolean type, denoted in C as Bool, and the numeration type (type code enum) have been added in C-99. However, in C++ language, the code for Boolean type is bool. C language also allows user-defined types such as names of structures, and unions.