Friday, 16 September 2011

Episode 2 : Variable, Data Type


Data Type

When we write program, we use different kind of data. Such as, integer number, floating number, character etc.

We use mainly four kind of data types.

·        char : A single character can be defined as a character (char) type data. Character are usually stored in 8 bits ( 1 byte) of internal storage.
Example : char a; there ‘a’ is character type data. We can store a single character to use this and it take 1 byte from the memory.

·        int :  Whole integer number can be defined as a integer (int) type data. int takes 16 bit (2 byte) from the memory. C has three classes of integer there are, short int, int, long int. short int represents fairly small integer values and long int to increase the range of values.
Example : int a; there ‘a’ is a int type data and it hold integer value.

·        float : Floating number can be defined by the ‘float’ type. It takes 32 bit(4 byte) from the memory for holding floating data.
Example : float a; there ‘a’ is float type data and it takes 4 byte memory for storing float type data.
·        double : A double data type number (combine of int and float) uses 64 bits. ‘double’ type represents the same data type that float represents, but with a greater precision.
Example : double a; there ‘a’ is a double type data and it takes 8 byte memory for storing data.


The following  table represent the range of the data type :

Type
Minimum allowed range
Typical allowed range
Typical size in bytes
char
 −127 → +127
or 0 → +255
−128 → +127
or 0 → +255
1
signed char
−127 → +127
−128 → +127
1
unsigned char
0 → +255
0 → +255
1
signed short int
−32767 → +32767
−32768 → +32767
2
unsigned short int
0 → +65535
0 → +65535
2
signed int
−32767 → +32767
−32768 → +32767 (antique systems)
−2147483648 → +2147483647
2 or 4
unsigned int
0 → +65535
0 → +65535 (antique systems)
0 → +4294967295
2 or 4
signed long int
−2147483647 → +2147483647
−2147483648 → +2147483647
−9223372036854775808 → +9223372036854775807 (64-bit systems)
4 or 8
unsigned long int
0 → +4294967295
0 → +4294967295
0 → +18446744073709551615 (64-bit systems)
4 or 8
signed long long int
−9223372036854775807 → +9223372036854775807
−9223372036854775808 → +9223372036854775807
8
unsigned long long int
0 → +18446744073709551615
0 → +18446744073709551615
8
float
1×10−37 → 1×1037
1×10−37 → 1×1037
4
double
1×10−37 → 1×1037
1×10−308 → 1×10308
8
long double
1×10−37 → 1×1037
1×10−308 → 1×10308
1×10−4932 → 1×104932
8, 12, or 16
 

Written by "Shojib"

No comments:

Post a Comment