C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.
                                     Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS DATA TYPES
Introduction
• You learned about three primary data types
  – char
  – int
  – float
• These primary data types can be of several
  types.
Integer
long & short       signed & unsigned
long and short
• Integer
  – On 16-bit OS : 2 Bytes
  – On 32-bit OS : 4 Bytes
• When we declare an integer it occupies 4 bytes
  on a 32 bit OS.
• Sometimes it may be more than required.
• Why waste memory?
• How to save?
short integer
• Declare a short integer.
           short int a; //OR
           short b;
•   It will take at least 2 bytes.
•   You will save 2 bytes.
•   shorts are never bigger than ints.
•   Format specifier : %d
long integer
• Declare a long integer.
           long int a; //OR
           long b;
•   It will take at least 4 bytes.
•   Helpful if you are working on 16-bit OS.
•   ints are never bigger than longs.
•   Format specifier : %ld
signed and unsigned
• Value stored in an integer is positive by default.
• In a 16 bit OS the range for an integer will be:
                    -32768 to 32767
• Some times we do not need negative value.
• Why waste half of the values???
• Use signed and unsigned variable in this case.
unsigned integer
• Declare a unsigned integer.
          unsigned int a; //OR
          unsigned b;
• It will store in 2 bytes on 16-bit OS.
• Range will be : 0 to 65535
• Format specifier : %u
signed integer
• Declare a signed integer.
          signed int a; //OR
          signed b; //OR
          int c;
• It will store in 2 bytes on 16-bit OS.
• Range will be : -32768 to 32767
• Format specifier : %d
integers
Data type            Range                       Bytes   Format
short signed int     -32768 to 32767             2       %d
short unsigned int   0 to 65535                  2       %u
signed int           -2147483648 to 2147483648   4       %d
unsigned int         0 to 4294967295             4       %u
long signed int      -2147483648 to 2147483648   4       %ld
long unsigned int    0 to 4294967295             4       %lu
character
character
• Character range : -128 to 127
            signed char c; //OR
            char c1;
•   128 means -128 in case of character.
•   129 means -127
•   unsigned character range : 0 to 255
•   Hence it will print all 256 available characters.
            unsigned char c;
float and double
• Both are used for storing floating point value.
• float occupies 4 bytes and it’s range is:-
  – -3.4e38 to +3.4e38
  – Format specifier : %f
• double occupies 8 bytes and it’s range is:-
  – -1.7e308 to +1.7e308
  – Format specifier : %lf
       double a;
long double
• If your demand is too high you can use it.
• long double occupies 10 bytes and it’s range is:
  – -1.7e4932 to +1.7e4932
  – Format specifier : %Lf
       long double a;
floating point
Data type     Range                    Bytes   Format
float         -3.4e38 to +3.4e38       4       %f
double        -1.7e308 to +1.7e308     8       %lf
long double   -1.7e4932 to +1.7e4932   10      %Lf
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

               For any problem in this tutorial mail me at
                     yogendra@learnbywatch.com
                         with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com
From Here To

STORAGE CLASS

Data types

  • 1.
    C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2.
    Keep your notebookwith you. Write important point and questions that comes in your mind Solve Mind band exercise. Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS DATA TYPES
  • 3.
    Introduction • You learnedabout three primary data types – char – int – float • These primary data types can be of several types.
  • 4.
    Integer long & short signed & unsigned
  • 5.
    long and short •Integer – On 16-bit OS : 2 Bytes – On 32-bit OS : 4 Bytes • When we declare an integer it occupies 4 bytes on a 32 bit OS. • Sometimes it may be more than required. • Why waste memory? • How to save?
  • 6.
    short integer • Declarea short integer. short int a; //OR short b; • It will take at least 2 bytes. • You will save 2 bytes. • shorts are never bigger than ints. • Format specifier : %d
  • 7.
    long integer • Declarea long integer. long int a; //OR long b; • It will take at least 4 bytes. • Helpful if you are working on 16-bit OS. • ints are never bigger than longs. • Format specifier : %ld
  • 8.
    signed and unsigned •Value stored in an integer is positive by default. • In a 16 bit OS the range for an integer will be: -32768 to 32767 • Some times we do not need negative value. • Why waste half of the values??? • Use signed and unsigned variable in this case.
  • 9.
    unsigned integer • Declarea unsigned integer. unsigned int a; //OR unsigned b; • It will store in 2 bytes on 16-bit OS. • Range will be : 0 to 65535 • Format specifier : %u
  • 10.
    signed integer • Declarea signed integer. signed int a; //OR signed b; //OR int c; • It will store in 2 bytes on 16-bit OS. • Range will be : -32768 to 32767 • Format specifier : %d
  • 11.
    integers Data type Range Bytes Format short signed int -32768 to 32767 2 %d short unsigned int 0 to 65535 2 %u signed int -2147483648 to 2147483648 4 %d unsigned int 0 to 4294967295 4 %u long signed int -2147483648 to 2147483648 4 %ld long unsigned int 0 to 4294967295 4 %lu
  • 12.
  • 13.
    character • Character range: -128 to 127 signed char c; //OR char c1; • 128 means -128 in case of character. • 129 means -127 • unsigned character range : 0 to 255 • Hence it will print all 256 available characters. unsigned char c;
  • 14.
    float and double •Both are used for storing floating point value. • float occupies 4 bytes and it’s range is:- – -3.4e38 to +3.4e38 – Format specifier : %f • double occupies 8 bytes and it’s range is:- – -1.7e308 to +1.7e308 – Format specifier : %lf double a;
  • 15.
    long double • Ifyour demand is too high you can use it. • long double occupies 10 bytes and it’s range is: – -1.7e4932 to +1.7e4932 – Format specifier : %Lf long double a;
  • 16.
    floating point Data type Range Bytes Format float -3.4e38 to +3.4e38 4 %f double -1.7e308 to +1.7e308 8 %lf long double -1.7e4932 to +1.7e4932 10 %Lf
  • 17.
    To get completebenefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com From Here To STORAGE CLASS