Wednesday, September 24, 2014

2.4 DATA TYPES


§  Data types are used to store various types of data that is processed by program.
§  Data type attaches with the variables the number of bytes to be allocated to variable and valid operations which can be performed on that variable.
§  C data types can be classified as follows:
                                i.            Primary(or Fundamental) Data type
§  Integer (int)
§  Character(char)
§  Floating Point (float)
§  Void
                              ii.            Derived data type
e.g. Pointers, Functions, Arrays
                            iii.            User-defined data type
e.g. struct, union, typedef
 
                                                               Fig 04: Primary Data Types


Integer Data Type
§  Integers are whole numbers with a range of values supported by a particular compiler.
§  Integers occupy one word of storage, and since the word sizes of compiler vary (typically, 16 or 32 bit) the size of an integer that can be stored depends on the computer.
§  C has three classes of integer storage, namely short int, int, and long int, in both signed and unsigned forms.

 
int (short int/signed int)
unsigned int
long int
Memory
2
2
4
Range
-32768 to + 32767
0 to +65535
-2147483648 to +2147483647
Format specifier
%d
%u
%ld

NOTE: The C Language defines two qualifiers - Sign & Unsign. In the case of "sign", one bit is reserved for storing the sign bit when the integer is represented in binary form. Whereas in case of qualifier ‘unsigned’, no bit is reserved for storing the sign and all the bits are used for storing the magnitude.

NOTE: The C Language defines two modifiers - Short & Long. "Short" is just another way to call the said data type. The "Long" modifier doubles the memory allocated to the said data type. 

Character Data Type
§  A single character can be defined as a character (char) type data.
§  Characters are usually stored in 8 bits (one byte) of internal storage.

 
signed char
unsigned char
Memory
1
1
Range
-128 to +127
0 to +255
Format specifier
%c
%c

NOTE: When char is printed using %d format specifier, it prints ASCII character.

Floating Point Data Type
§  Floating point (or real) numbers are stored in 32 bits (on all 16 bit and 32 bit machines), with 6 digits of precision.
§  A double data type number uses 64 bits giving a precision of 14 digits.

 
floating point
double
Memory
4
8
Range
3.4e -38 to 3.4e +38
1.7e -108 to 1.7e +108
Format specifier
%f
%lf


Void Data Type
§  The void data type has no values.
§  Void is used to specify the type of functions i.e. a function is said to be void when it does not return any value to the calling function.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.