Technical Aspects of Fundamental Data types in C
Fundamental Data types in C
Why do we need data types like integers, char, double, etc. in programming ?
In computer science and computer programming, a data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support basic data types of integer numbers (of varying sizes), Floating-point numbers (which approximate real numbers), characters and Booleans. A data type constrains the values that an expression, such as a variable or a function, might take. This data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored. A data type provides a set of values from which an expression (i.e. variable, function, etc.) may take its values.
Data types are used within type systems, which offer various ways of defining, implementing and using them. Different type systems ensure varying degrees of type safety.
Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology.
Common data types include:
Integer.
Floating-point number.
Character.
String.
Boolean.
In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.
The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. Headers for the C standard library, to be used via include directives, contain definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the language implementation on specific hardware platforms.
Interface to the properties of the basic types
Information about the actual properties, such as size, of the basic arithmetic types, is provided via macro constants in two headers: <limits.h> header (climits header in C++) defines macros for integer types and <float.h> header (cfloat header in C++) defines macros for floating-point types. The actual values depend on the implementation.
Properties of integer types
CHAR_BIT – size of the char type in bits (at least 8 bits)
SCHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN(C99) – minimum possible value of signed integer types: signed char, signed short, signed int, signed long, signed long long
SCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX(C99) – maximum possible value of signed integer types: signed char, signed short, signed int, signed long, signed long long
UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX(C99) – maximum possible value of unsigned integer types: unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long
CHAR_MIN – minimum possible value of char
CHAR_MAX – maximum possible value of char
MB_LEN_MAX – maximum number of bytes in a multibyte character
Properties of floating-point types
FLT_MIN, DBL_MIN, LDBL_MIN – minimum normalized positive value of float, double, long double respectively
FLT_TRUE_MIN, DBL_TRUE_MIN, LDBL_TRUE_MIN (C11) – minimum positive value of float, double, long double respectively
FLT_MAX, DBL_MAX, LDBL_MAX – maximum finite value of float, double, long double, respectively
FLT_ROUNDS – rounding mode for floating-point operations
FLT_EVAL_METHOD (C99) – evaluation method of expressions involving different floating-point types
FLT_RADIX – radix of the exponent in the floating-point types
FLT_DIG, DBL_DIG, LDBL_DIG – number of decimal digits that can be represented without losing precision by float, double, long double, respectively
FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON – difference between 1.0 and the next representable value of float, double, long double, respectively
FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG – number of FLT_RADIX-base digits in the floating-point significand for types float, double, long double, respectively
FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP – minimum negative integer such that FLT_RADIX raised to a power one less than that number is a normalized float, double, long double, respectively
FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP – minimum negative integer such that 10 raised to that power is a normalized float, double, long double, respectively
FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP – maximum positive integer such that FLT_RADIX raised to a power one less than that number is a normalized float, double, long double, respectively
FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP – maximum positive integer such that 10 raised to that power is a normalized float, double, long double, respectively
DECIMAL_DIG (C99) – minimum number of decimal digits such that any number of the widest supported floating-point type can be represented in decimal with a precision of DECIMAL_DIG digits and read back in the original floating-point type without changing its value. DECIMAL_DIG is at least 10.
https://www.encodetraining.com
Thanks
Mahesh V Kondawar
(Trainer)
encodetraining@gmail.com



Comments
Post a Comment