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
absolutely fantasti
Yes this is definitly the best webpage that I have ever viewed …ever !!!!!!!!!1
great work buddy..
great
good work
you should provide size for 32-bit compilers as 16-bits are now obsolete. Though nice article.
what is diff between signed n unsigned??
the difference between signed and unsigned is the SPELLING… gets? 😀
We just specify the signs of the assigned variables or constants and the range also gets doubled as -ve ones are not permissible
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
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…
Hi Its all good but there is a small correction to be made… The character is declared as alp =
I thought it was `A` not ‘A’
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…
no its correct ………short int,short unsigned int and short signed int its 2 bytes……….
So why here this is
good info……….
precise…very helpful for beginners..
more c samples please…:)
good webpage
What’s the difference between signed and unsigned (in modifiers)?
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…
GOOD………..
great collection
venkatt
well,what is signed char and unsigned char
why the turbo c have int of 2byte and
gcc have int of 4byte
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 🙂
nice one