Integer Data Type


                                               Integer Data Types

Integers are whole numbers with a range of values, range of values are machine dependent.
Generally an integer occupies 2 bytes memory space and its value range limited to -32768 to +32767 (that is, -215 to +215-1). A signed integer use one bit for storing sign and rest 15 bits for number.To control the range of numbers and storage space, C has three classes of integer storage namely short int, int and long int.
All three data types have signed and unsigned forms. A short int requires half the amount of storage than normal integer. Unlike signed integer, unsigned integers are always positive and use all the bits for the size of the number. Therefore, the range of an unsigned integer will be from 0 to 65535. The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space.



Syntax:
int <variable name>;
int num1;
short int num2;
long int num3;
int <variable name>=<value>;
int  num=6; 


Example: 5, 6, 100, 2500.


Integer Data Type Memory Allocation:





Short int
int
long int
1 byte
2 byte
4 byte
    
 




Signed integer :-
 

Integer take 2 byte of memory and 2 byte .One byte means 8 bits and 16 bits  means 2byte. 1 bit of 2 byte is reserved for sign negative and postive.
 

Explaination:-
   
     +/-        1 2 3 4
             |                                       |
      Signed bit                          Data Bit

                  215
this means that if we are using signed integer we can only use 15 bits of 2 byte.

Unsigned integer :-
Integer take 2 byte of memory and 2 byte .One byte means 8 bits and 16 bits  means 2 byte.  In this there is no sign and 2 byte is not reserved for sign negative and postive.

Explaination:-
   
2 3 4 5
                                      |
                                Data Bit

                  216
this means that if we are using unsigned integer we can only use 16 bits of 2 byte.we can use 2 byte.


Comments

Popular posts from this blog