Data Types in C
Data types tell the compiler what kind of data a variable will store and how much memory it needs.
They help the compiler allocate memory correctly and perform operations safely.
EASY LEVEL (Beginner Friendly)
Why Data Types Are Needed
- Different data needs different memory
- Numbers, characters, and decimals are stored differently
- Data types avoid confusion and errors
Main Types of Data Types in C (Easy)
1. Integer Type (int)
Used to store whole numbers.
int age = 20;Examples: -5, 0, 100
2. Character Type (char)
Used to store single characters.
char grade = 'A';Stores only one character at a time.
3. Floating Point Type (float)
Used to store decimal numbers.
float price = 99.50;4. Double Type (double)
Used to store large decimal values with more accuracy.
double distance = 12345.6789;5. Void Type (void)
Used when no value is returned.
void show() {
}EXPERT LEVEL (Technical & Exam-Oriented)
Classification of Data Types in C
1. Basic (Primitive) Data Types
| Type | Description |
int | Integer values |
char | Character data |
float | Decimal numbers |
double | High-precision decimals |
void | No value |
2. Derived Data Types
Derived from basic types.
| Type | Example |
| Array | int a[5]; |
| Pointer | int *p; |
| Function | int add(); |
3. User-Defined Data Types
Created by the programmer.
| Type | Purpose |
struct | Group different data types |
union | Share memory |
enum | Named constants |
typedef | Rename data types |
Memory Size (Typical)
| Data Type | Size |
char | 1 byte |
int | 4 bytes |
float | 4 bytes |
double | 8 bytes |
(Note: Size may vary by system/compiler)
Example Showing Data Types in Use
int count = 10;
char letter = 'C';
float marks = 85.5;
double avg = 92.3456;Each variable:
- Has a type
- Uses specific memory
- Supports type-specific operations
Key Expert Insights
- Data types define memory allocation
- They ensure type safety
- Correct data type choice improves performance
- Wrong data type can cause overflow or precision loss
One-Line Exam Answer
Data types in C specify the type of data a variable can store and determine the amount of memory allocated for it.
