Data Types in C

The above video is an extract from the online course – “C Programming: The ultimate guide for beginners” which we are currently working on. Consider subscribing to Youtube channel – Aptuts in order to get latest updates on new videos and online C programming course.

Data types in C 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 4 bytes of memory in 32-bit compiler
• float – occupies 4 byes of memory
• double – occupies 8 bytes of memory
• char – occupies 1 byte of memory

int data types in C is used to define integer numbers. It occupies 4 bytes of memory (32-bit C compiler)

				{
                                int amount;
                                amount = 5;
                }

float data type in C is used to define floating type numbers. It occupies 4 bytes of memory (32-bit C compiler)

                {
                                float amount;
                                amount = 1.200000;
                }

double data type is used to store big floating point numbers. It reserves 8 bytes of memory (32-bit C compiler)

                {
                                double amount;
                                amount = 1.200000000000;
                }

char is used to store characters. It occupies 1 byte of memory (32-bit C compiler)

                {
                                char alp;
                                alp = ‘A’;
                }

The modifiers define the amount of storage allocated to the variable.
Following are the four modifiers in C.
· short
· long
· signed
· unsigned

short can be used with int data-type.

long can be used with int and double data-type.

signed and unsigned can be used with both int and char data-types.

Using signed int is redundant as int is signed by default.

Following are the valid combinations of data types and modifiers in C:

Data type Format specifier Storage allocation in Bytes (32-bit compiler)
int %d 4
float %f 4
double %lf 8
char %c 1
short int %hd 2
long int %ld 4
long long int %lld 8
long double %Lf 12
signed int %d 4
signed short int %hd 2
signed long int %ld 4
unsigned int %u 4
unsigned short int %hu 2
unsigned long int %lu 4
unsigned long long int %llu 8
signed char %c 1
unsigned char %c 1

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

float <= double <=long double

Program to find memory allocation size of C data-types

You may also like...

28 Responses

  1. Anonymous says:

    absolutely fantasti

  2. Anonymous says:

    Yes this is definitly the best webpage that I have ever viewed …ever !!!!!!!!!1

  3. Rohitchamp says:

    great work buddy..

  4. Anonymous says:

    great

  5. Anonymous says:

    good work

  6. matneo says:

    you should provide size for 32-bit compilers as 16-bits are now obsolete. Though nice article.

  7. Anonymous says:

    what is diff between signed n unsigned??

  8. Anonymous says:

    sign refers to the positive or negative sign before integer
    no sign or unsigned means non negative integers
    now signed means it can take negative integers also

  9. vino says:

    if some ask me , write data types in c.
    what should i write? 14 data types or int,float,double,char only?

    ans me frds…

  10. Anonymous says:

    Hi Its all good but there is a small correction to be made… The character is declared as alp =

  11. Anonymous says:

    I thought it was `A` not ‘A’

  12. Anonymous says:

    i think for short int,short unsigned int and short signed int, its 1 byte on 16 bit compiler(As per ANSI C, Balagurusamy E,5e,Pg. 33)
    If its wrong, let me know pls…

  13. Anonymous says:

    no its correct ………short int,short unsigned int and short signed int its 2 bytes……….

  14. Vard says:

    So why here this is

  15. C V KASHYAP says:

    good info……….

  16. precise…very helpful for beginners..

  17. Anonymous says:

    more c samples please…:)

  18. Anonymous says:

    good webpage

  19. Hantenks says:

    What’s the difference between signed and unsigned (in modifiers)?

  20. Anonymous says:

    This site is very helpful in learnng c and i like it
    and have a request that please… provide some deep knowladge of these content inspite of just an overview…

  21. Anonymous says:

    GOOD………..

  22. venkat pott says:

    great collection

    venkatt

  23. akhil says:

    well,what is signed char and unsigned char

  24. patel dhruvit says:

    why the turbo c have int of 2byte and
    gcc have int of 4byte

    • Aditya Salunkhe says:

      It depends on architecture of the processor, if your gcc compiler runs on i386 instruction set ie 32 bit instruction set it will be 4 bytes, while on x86 machines it will be 8 bytes. As per the turbo c case im not sure if u are using dos-box emulator and the turboc compiler default size prefrence its diffrent for every compiler and you can change it too 🙂

  25. anon says:

    nice one

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet