Thursday, 11 February 2016

Data types in C and its size

My title
Data types in C and its size
C89 -[those features of C defined by the original, 1989 ANSI standard for C (commonly referred to as C89)]- defines five foundational data types
1. Character declared as char
2. Integer declared as int
3. Floating-point decalred as float
5. Double floating point declared as double
4. Valueless declared as void
Other several data types arederived from these basic data types.
Now, about the size and range of these data types we have heared many different things. Some people says that integer takes 2 bytes, some says it takes 4 bytes. It is true but not clear.
Most important, the size and range of these data types may vary among processor types and compilers.” However in all case char is 1 byte.
The size of an int is generally same as the word (The memory stores binary information in group of bits called words ) length of the execution environment of program.
For most 16-bit environments such as DOS, an int is 16 bits (2 bytes). For most 32-bit environments an int is 32 bits (4 bytes).
So, you can not be sure about the size of an integer if your program is going to be executed on the widest range of environments.
It is important to understand that C stipulates only the minimal range of each data type, not its size
in bytes.
Valid data type combinations supported by C, along with their minimal ranges and typical bit widths are given below. Remember, the table shows the minimum range that these types will have, not their typical range. For example, on computers that use two's complement arithmetic (which is nearly all), an integer will have a range of at least 32,767 to –32,768.
Type                               Typical Size in Bits                                              Minimal Range
char                                        8                                                                       –127 to 127
unsigned char                        8                                                                       0 to 255
signed char                            8                                                                       –127 to 127
int                                     16 or 32                                                                 –32,767 to 32,767
unsigned int                     16 or 32                                                                 0 to 65,535
signed int                         16 or 32                                                                Same as int
short int                               16                                                                     –32,767 to 32,767
unsigned short int               16                                                                      0 to 65,535
signed short int                   16                                                                     Same as short int
long int                               32                                                            –2,147,483,647 to 2,147,483,647
long long int                       64                                                    –(263 – 1) to 263 – 1 (Added by C99)
signed long int                    32                                                                      Same as long int
unsigned long int                32                                                                   0 to 4,294,967,295
unsigned long long int        64                                                       264 – 1 (Added by C99)
float                                    32                                             1E–37 to 1E+37 with six digits of precision
double                                 64                                            1E–37 to 1E+37 with ten digits of precision
long double                         80                                             1E–37 to 1E+37 with ten digits of precision

Reference:-C: The Complete Reference 4th Edition by Herbert Schildt

No comments:

Post a Comment

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...