Data types

Data types are used to declare variables before using them. The two basic uses of data type can be described as follows :- 
1. It tells compiler what the variable name is. 
2. It specifies what type of data variables will holds and the set of operations that can be performed on this data. 

Let us take a example to let you understand about the data type more in deep :- 

Consider a light switch , it has a set of two values as on and off and two operations as turn on and turn off. 
For Example :-. int x; 
Here int is a data type, which says only only int type of data can be stored here . 

TYPES OF DATA TYPE :- There are three type of data types. 

1. Primary data types 
2. User defined data types 
3. Drived data types


 PRIMITIVE DATA TYPE

In this data type ,a variable is a character or integer type or it is a float type or double type . All these have its own different tyes.
EXAMPLE OF PRIMITIVE DATA TYPE:- int, float, double, char . 

int

Integers are whole numbers that can have both zero, positive and negative values but no decimal values. For example, 0, -5, 10
TO DECLARE AN INTEGER TYPE VARIABLE WE WOULD WRITE IT AS -  
                                                   int a =15;
The size of int is usually 4 bytes (32 bits). And, it can take 232 distinct states from -2147483648 to 2147483647.

Float

  To declare a floating point number we would write it as float for example(1.1,2.7)
                                                   b=150.23; 
  1. Float data type allows a variable to store decimal values.
  2. Storage size of float data type is 4. This also varies depend upon the processor in the CPU as “int” data type.

Char

To declare the    character point number we would write it as 
                                                        char Key='A'
 here char is the data type(primitive data type) and he is a variable of which contains the character type data i.e.,  
  1. Character data type allows a variable to store only one character.
  2. Storage size of character data type is 1. We can store only one character using character data type.

DRIVED DATA TYPES :-

Derived datatypes are composed of fundamental datatypes. Some fundamental datatypes as we discussed earlier i.e., primitive data type are:-- int, char, float, void etc. 
Derived datatypes are arrays, structures, pointers etc. ... Integers are used to store integer type data, not the floating point number. 


USER DEFINED DATA TYPE:-

A user-defined data type (UDT) is a data type that derived from an existing data type. You can use UDT’s (user defined data Type) to extend the built-in types already available and create your own customized data types. FOR EXAMPLE :-- Structure , union, type definition and enumerated data types.

NOW let us see the how many storage does these data type take :--

DATA TYPEMEMORY (BYTES)RANGEFORMAT SPECIFIER
char1-128 to 127 or 0 to 255 %c
unsigned char 10 to 255%c
signed char1-128 to 127%c
int2 or 4-2,147,483,648 to 2,147,483,647%d
unsigned int2 or 40 to 65,535 or 0 to 4,294,967,295 %d
 int short232,768 to 32,767%hd
unsigned short int20 to 65,535%hu
long89223372036854775808  to
9223372036854775807
%ld
unsigned long80 to 18446744073709551615 %lu

Floating-Point Types 

The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision −

DATA TYPEMEMORY (BYTES)RANGEPrecision
float41.2E-38 to 3.4E+38 6 decimal places
double82.3E-308 to 1.7E+30815 decimal places
long double103.4E-4932 to 1.1E+493219 decimal places