Data type is type of data according to the nature and use of data. Every data type has limited size and range of values it can hold. There are two types of data types.
Data Type Modifier : Data type modifiers modify the base data types. There are two types of modifiers.
You will get examples of all data types and modifier in further blogs.
- Primary Data Type
- int
- float
- char
- void
- Secondary Data Type
- Array
- Pointer
- Structure (struct)
- Union (union)
- Enumeration (enum)
- int: It represent integer number. As stated above it has limited size depend on compiler and platform for which it is targeted. Size of int for 16 bit platform and compiler is 16 bit (2 Byte), for 32 bit platform and compiler is 32 bit (4 Byte) and so on. Range of int is depend on its size, we can get by following formula
-(2 n-1) to 2 n-1
-
float: It represent real numbers. Its size is 32 bit (4 Byte) and its range is ±1.18 x 10-38 to ±3.4 x 1038.
- char: It represent character/symbols. Its size is 8 bit (1 Byte) for ASCII standard. As char and int values are interchangeable according to ASCII standard, it can be used as 1 Byte integer in C/C++ language.
- void: It represent no type, so doesn't have any size or range.
Data Type Modifier : Data type modifiers modify the base data types. There are two types of modifiers.
- Sign Modifier
- signed It distributes half of the range of integer, long and char to negative. By default all data types are signed therefore there is no need to use it.
- unsigned It make full range of integer, long and char to positive. Since all data types are signed by default, we explicitly declare unsigned data types to get more values in positive side.
- Range Modifier
- short It has size of at least 16 bit (2 Byte) or half of the bits of integer size depend on OS to decrease the size and range of int.
- long It has size of double bits of integer size depend on OS to increase the size and range of int. It can be used with double to further increase size and range of float.
- double It has size of double bits of float size to increase the size and range of float.
You will get examples of all data types and modifier in further blogs.
No comments:
Post a Comment