ANSI C Data Types
- The ANSI standard for C is limited to four data types.ANSI image by DBX60 from Fotolia.com
The American National Standards Institute (ANSI) standard for the C computer programming language remains true to the minimalist tenets of its original design. Many programmers are surprised to find that the language supports only four base data types. These core types establish the foundation for modeling more complex data elements such as strings and as substitutes for other simple types such as Boolean data. - The char data type is used for the representation of individual characters. It stores a signed numeric range of -127 to 127 in a single byte, using seven bits for the value and the eighth for the sign. The numeric values are linked to the ordered representation of the ASCII character set. A value of 65, for example, assigned to a char variable translates to the upper-case "A" in the ASCII set. Unsigned char variables do not use the sign bit, extending the value range from 0 to 255.
- An integer data type is used to store whole numbers. Different bit-size integer types are supported by the standard in order to accommodate numbers of various lengths without wasting storage space. A standard integer is 32 bits (4 bytes) in length, allowing the storage of numbers from -2,147,483,648 to 2,147,483,647. Short-integer variables use half of the memory allocation, 16 bits, if a smaller numeric range is needed. Long integers expand the storage to 64 bits. The integer type is also modified by the unsigned designation, doing away with sign bit if negative numbers are not going to be stored.
- The float data type is designated to store values that contain a fractional portion marked by a decimal point, such as 3.15. The float type is a single-precision value stored in a 32-bit variable in three parts. One bit is assigned to the sign, 8 bits to the exponent and 23 bits are used to hold the mantissa. The float notation represents the floating point number as a fraction (the mantissa) that is raised by the power of the exponent to place the decimal point in the number. For example, to store the sample value 1.2345, the exponent is set to 1 and the mantissa is 617250. To compute the decimal number, the equation value = mantissa x (2 x exponent) [1.2345 = .617250 x 2] is used.
- The double type is an expanded float data type. It uses a 64-bit storage location in order to store numbers with 14 to 15 digits of precision. The 64 bits are broken down into a one-bit sign, 11 bits for the exponent and 52 bits for the mantissa.