Data Types in C



Data types determine the following:
     • Range of the data
     • Type of the data stored
     • Number of bytes it occupies in memory

C supports following data types:
     • int – occupies 2 (16-bit compiler) or 4 bytes (32-bit compiler) of memory
     • float - occupies 4 byes of memory
     • double – occupies 8 bytes of memory
     • char – occupies 1 byte of memory

int is used to define integer numbers. It occupies 2 bytes of memory (16-bit compiler)
                {

                                int amount;
                                amount = 5;
                }


float is used to define floating type numbers. It occupies 4 bytes of memory (16-bit compiler) 
                {
                                float amount;
                                amount = 1.200000;
                }

double is used to store big floating point numbers. It reserves 8 bytes of memory (16-bit compiler) 
                {
                                double amount;
                                amount = 1.200000000000;
                }

char is used to store characters. It occupies 1 byte of memory (16-bit compiler) 
                {
                                char alp;
                                alp = ‘A’;
                }


The modifiers define the amount of storage allocated to the variable.
 int, float and double have the following four modifiers.
·         short
·         long
·         signed
·         unsigned


long is used to store long int
short is used to store short int
long double is used to store long double
Using signed int is redundant as int is signed by default.
Modifier long can be applied to double data type.

Following are the valid combinations:
                long int or long (For 16 bit compiler: 4 byte)
                short int or short (For 16 bit compiler: 2 byte)
                signed int or int (For 16 bit compiler: 2 byte)
                unsigned int (For 16 bit compiler: 2 byte)
                short unsigned int
                long unsigned int
                char (Occupies 1 byte of memory)
                signed char or char (Range: -128 to +127, Occupies 1 byte of memory)
                unsigned char (Range: 0 to 255, Occupies 1 byte of memory)
                long double (Occupies 10 bytes of memory)

Following rule applies:
                short int <= int <= long int
                float <= double <=long double

Summary:
                
Following table is applicable for 16-bit compiler.
                
                Data Type                                            Bytes
                short int                                                2
                short unsigned int                                  2
                short signed int                                      2
                signed int                                              2
                unsigned int                                           2
                long int                                                  4
                long unsigned int                                    4
                long signed int                                        4
                float                                                      4
                double                                                   8
                long double                                            10
                char                                                       1
                signed char                                             1
                unsigned char                                         1


Responses

0 Respones to "Data Types in C"

Post a Comment

 

Total Pageviews

Return to top of page Copyright © 2011 | Kuppam Engineering College Converted into Blogger Template by Mohan Murthy