Primary DataType
ANSI C language provides 3 types of data types:
- Primary Data type:
- Derived Data type:
- User-defined Data type:
1] Primary data-type:
All c compilers support five fundamental datatypes namely integer(int), character(char), floating-point(float), double-precision floating-point (double), void(void).Many of them also offer extended datatypes such as long int and long double.
- character - keyword used is char
- integer - keyword used is int
- floating-point - keyword used is float
- double-precision floating-point - keyword used is double
- void(valueless) - keyword used is void
Size and range of datatypes on 16-bits machine:-
| data types | size(in bits) | range |
|---|---|---|
| char | 8 | –128 to 127 |
| int | 16 | –32768 to 32767 |
| float | 32 | 1.17549 × 10 –38 to 3.40282 × 10 38 |
| double | 64 | 2.22507 × 10 –308 to 1.79769 × 10 308 |
| void | 8 | valueless |
Note: Size and range of integer on 32 bits machine are 32 and –2147483648 to 2147483647.
Other data types as it is in 32 bits machine.
- Data Type is used to define the name and size of the variable.
int a;
//int=data type (Integer) a=variable
- The fundamental data types in C are int, char, float, double.
- Modifier includes signed, unsigned, short, long.
What is a modifier in C?
Sign-Sign/Unsigned
Size-Long/Short
- The amount of memory space to be allocated for a variable is derived by modifiers.
- Modifiers are prefixed with basic data types to modify (either increase or decrease) the amount of storage space allocated to a variable.
- Modifiers are prefixed with basic data types to modify (either increase or decrease) the amount of storage space allocated to a variable.
- For example, storage for the int data type is 4 byte for the 32-bit processor. We can increase the range by using long int which is 8 byte. We can decrease the range by using short int which is 2 byte.
Range:
- The maximum and minimum value that can be stored in the variable is called the range of that variable.
1 byte = 8 bits
2 bytes = 16 bits
3 bytes = 24 bits
4 bytes = 32 bits
If int is of 2 bytes. i.e 16 bits.
According to binary number system 216 =65536
Therefore the variable or a constant of type int of 2 bytes can have 65536 number. If I divide it by 2 then it will be 32768.
The minimum value possible is -32768.
The maximum value possible to store is +32768.
So, the range of int of 2 Bytes is from (-32768) to (+32767)
If int is a 4 bytes i.e 32 bits.
According to binary number system 232 = 2147483648.
Therefore the variable or a constant of type int of 4 bytes can have 4296947296 number. If I divide it by 2 then it will be 2, 147, 483, 648.
The minimum value possible is -2, 147, 483, 648.
The maximum value possible is +2, 147, 483, 647.
So, the range of int of 4 Bytes is from (-2, 147, 483, 648) to ( +2, 147, 483, 647)
If int is of 2 bytes. i.e 16 bits.
According to binary number system 216 =65536
Therefore the variable or a constant of type int of 2 bytes can have 65536 number. If I divide it by 2 then it will be 32768.
The minimum value possible is -32768.
The maximum value possible to store is +32768.
So, the range of int of 2 Bytes is from (-32768) to (+32767)
If int is a 4 bytes i.e 32 bits.
According to binary number system 232 = 2147483648.
Therefore the variable or a constant of type int of 4 bytes can have 4296947296 number. If I divide it by 2 then it will be 2, 147, 483, 648.
The minimum value possible is -2, 147, 483, 648.
The maximum value possible is +2, 147, 483, 647.
So, the range of int of 4 Bytes is from (-2, 147, 483, 648) to ( +2, 147, 483, 647)
i] Integer Data-type:
Integer datatype divided into signed and unsigned types as below.
signed unsigned
signed int unsigned int
signed short int unsigned short int
signed long int unsigned long int
signed unsigned
signed int unsigned int
signed short int unsigned short int
signed long int unsigned long int
Type
|
Size(bytes)
|
Range
|
|---|---|---|
| int or signed int | 2 | -32,768 to 32767 |
| unsigned int | 2 | 0 to 65535 |
| short int or signed short int | 1 | -128 to 127 |
| unsigned short int | 1 | 0 to 255 |
| long int or signed long int | 4 | -2,147,483,648 to 2,147,483,647 |
| unsigned long int | 4 | 0 to 4,294,967,295 |
Size in bits of int datatype in different bits machine:
In any C compiler, the size of integers datatype is restricted by the following rules.
Type
|
16 bits machine
| 32 bits machine | 64 bits machine |
|---|---|---|---|
short int
|
4
|
2
|
2
|
int
|
8
|
4
|
4
|
long int
|
10
|
4
|
8
|
- The minimum size of a short int is two bytes.
- The size of an int must be greater than or equal to that of a short int.
- The size of a long int must be greater than or equal to that of an int.
- The minimum size of a long int is four bytes.
i] Floating Data-type:
Floating point type used to store real numbers.
Type
|
Size(bytes)
|
Range
|
|---|---|---|
Float
|
4
|
3.4E-38 to 3.4E+38
|
double
|
8
|
1.7E-308 to 1.7E+308
|
long double
|
10
|
3.4E-4932 to 1.1E+4932
|
i]Character Data-type:
Character Datatype used to store character value.
Character types also divided in signed and unsigned types.
Type
|
Size(bytes)
|
Range
|
|---|---|---|
char or signed char
|
1
|
-128 to 127
|
unsigned char
|
1
|
0 to 255
|
iv] Void Data-type:
Void types mean no value. This is usually to specify the types of function which returns nothing.
Note: It is not used to declare a variable.
All tables are for only 16 bits machine.
Note: It is not used to declare a variable.
All tables are for only 16 bits machine.

Comments
Post a Comment