C language is rich in data types. Storage presentations and machine instructions for managing constants differ from machine to machine. The variety of data available allows the programmer to select the type according to the needs of the machine as well as the applications.
C supports three types of data types:
The types of primary sections and their extensions are discussed in this section. User-defined data types are defined in the next section when discussing derived data types such as arrays, methods, structures, and pointers and when they are encountered.
All C compilers support five basic data types, such as integer (int), character (char), floating-point (float), double-precision floating-point (double), and void. Many of them also offer extended data types like long inter and long double. The different data types and the terms used to describe them are given in the picture below. The basic four types of the range are given in the table.
|Data type||Range of values|
|char||-128 to 127|
|int||-32,768 to 32767|
|float||3.4e-38 to 3.4e+e38|
|double||1.7e-308 to 1.7e+e308|
Integers are whole numbers with different value values supported by a particular machine. Typically, integers occupy a word of storage, and the size of the machines differs from the size of an integer that can be stored. If we use a 16-bit word length, the size of the integer value is limited to -32768 to 32767. A uses one bit for a signed integer symbol and 15 bits for the width of the number. Similarly, a 32-bit word length can store an integer from -2147483648 to 2147483647.
To provide some control over the range of numbers and storage space, C has three integer storage, short int, int, and long int, both signed and unsigned forms. C defines these types so that they can be organized from smallest to largest, as shown in the image on the right. For example, the short int represents fairly small integer values and requires half the amount of storage used as a regular int number. Unlike signed integers, unsigned integers use all bits for the width of the number and are always positive. Thus, for a 16-bit machine, the number of unsigned integers would be from 0 to 65535.
We declare long and signed integers to increase the value limit. The use of qualifiers signed over integers is optional because the default declaration holds a signed number.
|char or signed char||8||-128 to 127|
|unsigned char||8||0 to 255|
|int or signed int||16||-32768 to 32767|
|unsigned int||16||0 to 65535|
|short int or signed short int||8||-128 to 127|
|unsigned short int||8||0 to 255|
|long int or signed long int||32||-2147483648 to 2147483647|
|unsigned long int||32||0 to 4294967295|
|float||32||3.4E - 38 to 3.4E+38|
|double||64||1.7E - 308 to 1.7E+308|
|long double||80||3.4E - 4932 to 1.1E+4932|
Floating-point numbers are stored in 32 bits with precise 6 digits. Floating-point numbers are defined by the keyword float in C. When the accuracy provided by the floating number is not sufficient, double type can be used to define the number. A double data type number uses 64 bits with a 14-digit accuracy. These are known as double-precision numbers. Note that the double type represents the same data type that the floating represents, but with more precision. To further extend the precision, we can use a long double that uses 80 bits. The relationship between the floating type is illustrated in the picture on the right.
The void type has no values. This is usually used to specify the type of methods. The type of a function is said to be void when it does not return any value to the calling method. It can also play the role of a generic type, meaning that it can represent any of the other standard types.
A single character can be defined as character (char) type data. Characters are usually stored in 8-bit internal storage. The signed or unsigned selector can be clearly applied to the char. Signed letters have values between 0 and 256, but signed letters have values between -128 and 127.