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();
- }
Output
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 8, 2017, 2:02 AM
Good Example Rupesh.
Rupesh KahanePosted Oct 20, 2016, 3:08 AM
Thanks Subash
SubashPosted Oct 20, 2016, 2:57 AM
Nice explanation
Rupesh KahanePosted Dec 30, 2015, 12:43 PM
thanks to Santhakumar Munuswamy sir
Santhakumar MunuswamyPosted Nov 29, 2015, 11:50 PM
Good one
Rupesh KahanePosted Nov 28, 2015, 6:46 AM
thanks a lot Sibeesh Venu & Gopi Chand also
Rupesh KahanePosted Nov 28, 2015, 6:45 AM
thanks Harshad Pansuriya
Gopi ChandPosted Nov 28, 2015, 3:30 AM
Great one
Sibeesh VenuPosted Nov 28, 2015, 2:38 AM
Nice Share
Harshad PansuriyaPosted Nov 27, 2015, 11:07 PM
Nice one
Rupesh KahanePosted Nov 27, 2015, 5:39 AM
thanks to all Ajay Gandhi, Raja T, Aqib Shehzad
Rupesh KahanePosted Nov 27, 2015, 5:19 AM
Thanks to Prasham Sabadra sir also
Rupesh KahanePosted Nov 27, 2015, 5:19 AM
Thanks Ankur Mistry
Muhammad Aqib ShehzadPosted Nov 27, 2015, 4:57 AM
good elaboration
Raja TPosted Nov 27, 2015, 4:31 AM
Nice, Thanks for sharing
Ajay GandhiPosted Nov 27, 2015, 4:13 AM
Nice One
Prasham SabadraPosted Nov 27, 2015, 3:59 AM
Thanks for sharing :)
Ankur MistryPosted Nov 27, 2015, 3:44 AM
Nice