Data Types:
- Data types are an important attribute of an identifier in any language because all operations are type checked by compiler for the compatibility.
- Data type determines all the possible values that an identifier can have and valid operations that can be applied on it. Illegal operations will not compile by compiler.
C language has the following categories:
Primitive / Basic Data Types
- Character (Char)
- Integer (Int)
- Single Precision Floating Point (Float)
- Double Precision Floating Point (Double)
- No value Available (Void)
Derived Data Types
- Array Types
- Pointer Type
- Function Types
User Defined Data Types
- Structure
- Union
- Enumeration
Data types & their memory requirements:
| SR | Data Types | Memory in Bytes |
| 1 | char | 1 Byte |
| 2 | int | 2 Byte |
| 3 | float | 4 Bytes |
| 4 | double | 8 Bytes |
| 5 | signed | Same as data types 1, 2 |
| 6 | Unsigned | Same as data types 1, 2 |
| 7 | short int | 2 Bytes |
| 8 | long int | 4 Bytes |
| 9 | long float | 8 Bytes |
| 10 | long double | 10 Bytes |
Format Specifiers in C Language
| S.No | Data Type | X | Format Specifies | Remark |
| 1 | Char | C | %c | Single character |
| 2 | Int | I | %i | Signed Integer |
| 3 | Int | D | %d | Signed Integer in decimal number system |
| 4 | unsigned int | O | %o | Signed integer in octal number system |
| 5 | unsigned int | u | %u | Signed integer in decimal number system |
| 6 | unsigned int | X | %x | Signed integer in hexadecimal number system |
| 7 | unsigned int | X | %X | Signed integer in hexadecimal number system |
| 8 | long int | Id | %%Id | Signed long |
| 9 | short int | Hd | $hd | Signed short |
| 10 | unsigned long | Lu | %lu | Unsigned long |
| 11 | unsigned short | Hu | %hu | Unsigned short |
| 12 | float | F | %f | Signed precision float |
| 13 | Double | Lf | %If | Signed double precision float |
| 14 | String type | S | %s | String |
| 15 | Pointer type | P | %p | Pointer |
Program
- #include<stdio.h>
- #include<conio.h>
- main()
- {
- printf("********* size of various data types *********\n");
- printf("\n character takes %d bytes in memory \n", sizeof(char));
- printf("\n integer takes %d bytes in memory \n",sizeof(int));
- printf("\n float takes %d bytes in memory \n",sizeof(float));
- printf("\n double takes %d bytes in memory \n",sizeof(double));
- getch();
- }

Real life example
Suppose if we are giving any interview then let say interviewer ask the following questions:

Question: What is your designation in your current company?
Answer: Software Developer
In the above scenario whenever we think about answer, we decide the data type of our answer like it will be character string.
Question: What is your current CTC?
Answer: x Lac
In the above scenario whenever we think about answer, we decide data type of our answer like it will be in numbers (can be integer or float).
Summary
This article will help fresher candidates to understand Data Types in C with real life example.
Hope you enjoyed this one.


Ankur SohalPosted Dec 7, 2017, 9:02 PM EST
Good Example Rupesh.
Rupesh KahanePosted Oct 19, 2016, 11:08 PM EDT
Thanks Subash
SubashPosted Oct 19, 2016, 10:57 PM EDT
Nice explanation
Rupesh KahanePosted Dec 30, 2015, 7:43 AM EST
thanks to Santhakumar Munuswamy sir
Santhakumar MunuswamyPosted Nov 29, 2015, 6:50 PM EST
Good one
Rupesh KahanePosted Nov 28, 2015, 1:46 AM EST
thanks a lot Sibeesh Venu & Gopi Chand also
Rupesh KahanePosted Nov 28, 2015, 1:45 AM EST
thanks Harshad Pansuriya
Gopi ChandPosted Nov 27, 2015, 10:30 PM EST
Great one
Sibeesh VenuTOP 100Posted Nov 27, 2015, 9:38 PM EST
Nice Share
Harshad PansuriyaPosted Nov 27, 2015, 6:07 PM EST
Nice one
Rupesh KahanePosted Nov 27, 2015, 12:39 AM EST
thanks to all Ajay Gandhi, Raja T, Aqib Shehzad
Rupesh KahanePosted Nov 27, 2015, 12:19 AM EST
Thanks to Prasham Sabadra sir also
Rupesh KahanePosted Nov 27, 2015, 12:19 AM EST
Thanks Ankur Mistry
Muhammad Aqib ShehzadPosted Nov 26, 2015, 11:57 PM EST
good elaboration
Raja TPosted Nov 26, 2015, 11:31 PM EST
Nice, Thanks for sharing
Ajay GandhiPosted Nov 26, 2015, 11:13 PM EST
Nice One
Prasham SabadraPosted Nov 26, 2015, 10:59 PM EST
Thanks for sharing :)
Ankur MistryTOP 100Posted Nov 26, 2015, 10:44 PM EST
Nice