Data Types in C (int, float, char, double, void)
💻 Data Types in C (int, float, char, double, void)
In C programming (created by Dennis Ritchie), data types tell the computer:
👉 what kind of data you are storing
👉 how much memory to allocate
🔹 What is a Data Type? 🤔
A data type defines:
- Type of value (number, character, etc.)
- Memory size
- Range of values
🔹 Main Data Types in C
🔸 1. int (Integer) 🔢
Used to store whole numbers
✅ Example:
int a = 10;
👉 Stores values like: -5, 0, 100
📌 Size: usually 4 bytes
🔸 2. float (Decimal) 🌊
Used to store decimal (fraction) numbers
✅ Example:
float price = 99.5;
👉 Stores values like: 3.14, 0.5
📌 Size: 4 bytes
📌 Precision: up to ~6 decimal digits
🔸 3. char (Character) 🔤
Used to store single character
✅ Example:
char grade = 'A';
👉 Stores: 'A', 'b', '1'
📌 Size: 1 byte
🔸 4. double (Double Precision) 🎯
Used to store large decimal numbers with high precision
✅ Example:
double pi = 3.1415926535;
📌 Size: 8 bytes
📌 More accurate than float
🔸 5. void (No Value) 🚫
Used when no value is needed
✅ Example:
void display() {
printf("Hello");
}
👉 Means:
- Function does not return any value
🔹 Quick Comparison Table 🆚
| Data Type | Use | Example | Size |
|---|---|---|---|
| int | Whole numbers | 10 | 4 bytes |
| float | Decimal numbers | 3.14 | 4 bytes |
| char | Single character | 'A' | 1 byte |
| double | Large decimals | 3.14159 | 8 bytes |
| void | No value | — | 0 |
🔹 Simple Program Example 🧠
#include <stdio.h>
int main() {
int a = 10;
float b = 5.5;
char c = 'A';
double d = 3.14159;
printf("%d %f %c %lf", a, b, c, d);
return 0;
}
🔹 Format Specifiers 📢
Used in printf() to print values:
| Data Type | Format |
|---|---|
| int | %d |
| float | %f |
| char | %c |
| double | %lf |
🔹 Final Concept 🔥
👉 Data types decide:
- what you store
- how much memory is used
📝 Summary
-
int→ whole numbers 🔢 -
float→ small decimals 🌊 -
double→ large/precise decimals 🎯 -
char→ single character 🔤 -
void→ no value 🚫
Comments
Post a Comment