C Data Types

Data Types:

The ‘C’ programming language provides a rich set of data types. The Data type defines the set of value that can be stored, type of value and also defines the size of memory allocated to the variable. The ‘C’ language Data type can be classified as:
    
1. Primary Data types:

  These data types are fundamental data types of the language. They are  
1. Integer data type 
2. Float  (or) real data type
3. Character data type 
4. Void data type

2. Derived Data types: 

These data types are designed using the primary data types. They are usually Arrays,
     Structures, Unions, Pointers, Functions etc,.

3. User defined Data types: 

These are new data types designed by the programmer for specific application.
     These are designed using typedef and enum. The general representation for declaring a variable for a type is
     done as shown below: data_type     variable_name; 

Integer Data type:

 In mathematics integers are whole numbers (no decimal point). The integer data type supports three categories of integer data type to support wide verity of values. They are short int, int and long int data types. And each data type can be either signed or unsigned data type to support both positive and negative values.  Example:  435, -10500, +15, -25, 32767 etc.

The integer data type occupies one word of storage, and since word size of machine/computer   varies, the size of the integer data type depends on the computer. And note that a signed integer uses one bit for sign and rest of the bits for magnitude of the number. The table shows notation, size, range of values, data type character.




Data type Notation
Size in
Bytes
Range of values
Data type character
signed short int / short int / short
1 Byte
-128  to +127
(-27  to +27-1)
%hd
unsigned short int / unsigned short
1 Byte
0  to  255
(0  to 28-1)
%hu
signed int / int
2 Byte
-32,768  to +32,767
(-215  to +215-1)
%d
unsigned int / unsigned
2 Byte
0  to  65,535
(0  to 216-1)
%u
signed long int / long int / long
4 Byte
-2,147,483,648  to 2,147,483,647
(-231  to  + 231-1)
%ld
unsigned long int / unsigned long
4 Byte
0  to  4,294,967,295
(0  to 232-1)
%lu
long long int
8 Byte
–263 to 263 – 1
(Added by C99)
unsigned long long int
8 Byte
 264 – 1
(Added by C99)


Float/Real Data type: 
  
The float data type supports larger vales than integer data type and also supports more accuracy/efficiency of value than integer. The float value has a integer part and fractional part that are separated by a decimal point. It supports both decimal point notation and scientific notation to represent float values.
Example:   3.01234, 0.00034, 1234.0  à Decimal point notation.
                    15.0e-04 (0.0015), 2.345e2 (234.5), 12e5 (1200000.0)  à Scientific notation.
The float data type occupies generally 4 words of storage with 6-digits of precision (no. of digits of after decimal point). The precision can be increased to increase accuracy. The table shows notation, size, range of values, data type character.





Data type Notation
Size in
Bytes
Range of values
Data type character
float
 (single precision up to 6 digits )

4 Byte
-3.4 x 10 -38   to  3.4 x 10 38   
%f   or   %e
double
(double precision up to 14 digits)
8 Byte
-1.7 x 10 -308   to 1.7 x 10 +308       
%lf
long double
(extended double precision 22 digits)
10 Byte

3.4  x10 -4932 to 1.1 x 10+4932

%Lf

Character data type: 

The character data type can store a single character value, i.e., a letter, a digit, a special symbol. Each character is enclosed in single quotes. The character data type can be either signed or unsigned. The character data type occupies 1-byte of storage.  Example:  ‘a’,  ‘2’,  ‘R’,  ‘;’  etc.
The table shows notation, size, range of values, data type character.




Data type Notation
Size in
Bytes
Range of values
Data type character
signed char / char
1 Byte
-128 to +127
%c
unsigned char
1 Byte
0 to 255
%c


Void data type: The void data type has no values. It can play a role of generic type, meaning that it can represent any of  the other data type vales. This void type usually used to specify the type of functions. The type of function is said to be void when it does not return any value to the calling function.