Introduction to Modifiers

MODIFIRES
They are special keywords which are used with the built-in data type. They are used to increase the storage capacity of variables. ’C’language provides four modifiers. They are
1.      short
2.      long
3.      signed
4.      unsigned

1]. short:-It is used to allocate half number of bytes then the actual size of a variable. Some ‘C’ compiler allocate four byte to normal integer type variable but its storing capacity remains from -32768 t0 32767.In such situation we can use short modifier. The short keyword is used to declare this type of variable. There is no format specifier for short.

Syntax: -         short Data-Type Variable-Name;
Ex: -                short int Num1;                                   -32768 to 32767
                        short float Num2;                                3.4e-38 to 3.4e+38
                        short char Ch;                                      -128 to 127

Ex:-
#include<stdio.h>
#include<conio.h>
void main()
{
            short int Num1= 1 ;
            short float Num2=10.2;

            clrscr();

            printf("\n%i",Num1);
            printf("\n%f",Num2);
            getch();
}

Output:-
            1
            10.200000


2]. long:-This modifier is used to increase the storage capacity of variable but requires some extra bytes. The long keyword is used to declare such types of variable. There is %l or %L format specifier for long.
Syntax: -         long Data-Type Variable-Name;

Ex: -                long int Num1;                                    -2147483648 to 2147483647
long float Num2;                                
long char Ch;                                       //No Impact

Ex:-
#include<stdio.h>
#include<conio.h>
void main()
{
            long int Num= 50000 ;
            clrscr();

            printf("\n%li",Num);
            getch();
}

Output:-
            500000

3]. signed:-It is the default modifier for the entire declared variable in ‘C’ language. This modifier allows the user to store both positive and negative values into a variable. There is no format specifier for signed.
Syntax: -         signed Data-Type Variable-Name;
Ex: -                signed int Num1;                                -23768 to 32767
                        Signed float Num2;                            3.4e-38 to 3.4e+38
                        Signed char ch;                                   -128 to 127

Ex:
#include<stdio.h>
#include<conio.h>
void main()
{
            signed int Num1=10 ;
            signed int Num2=-10;
            clrscr();
            printf("\n%d",Num1);
            printf("\n%d",Num2);
            getch();
}
Output:-
              10
-10
4]. unsigned:-This modifier allows the user to store only positive number into a variable. The unsigned keyword is used to declare such type of variable. The storage capacity becomes double. There is %u format specifier for unsigned.
Syntax: -         unsigned Data-Type Variable-Name;
Ex: -                unsigned int Num1;                            0 to 65535
unsigned float Num2;
unsigned char ch;                                0 to 255

Note:-If we store the negative values into the unsigne variables then compiler does not display any error message.

Ex:-
#include<stdio.h>
#include<conio.h>
void main()
{
            unsigned int Num1= 1 ;
            unsigned int Num2=-1;

            clrscr();

            printf("\n%u",Num1);
            printf("\n%u",Num2);
            getch();
}

Output:-
            1
            65535





Ex:-WAP which show the memory occupy by the modifiers.
#include<stdio.h>
#include<conio.h>
void main()
{
            short int Num1;
            long int Num2;

            short char c1;
            long char c2;

            short float f1;
            long float f2;

            clrscr();

            printf("\nShort int Memory Size is %i",sizeof(Num1));
            printf("\nLong int Memory Size is %i",sizeof(Num2));

            printf("\nShort char Memory Size is %i",sizeof(c1));
            printf("\nLong char Memory Size is %i",sizeof(c2));

            printf("\nShort Float Memory Size is %i",sizeof(f1));
            printf("\nLong Float Memory Size is %i",sizeof(f2));
            getch();
}


Output:-
            Short int Memory Size is 2
            Long int Memory Size is 4

            Short char Memory Size is 1
            Long char Memory Size is 1

            Short Float Memory Size is 4

            Long Float Memory Size is 8

Comments