C Character Data Types
🔤 C Character Data Types (Complete Guide: Beginner → Advanced)
In C language, the character data type is used to store single characters or small numeric values (ASCII codes).
It is 1 byte in size and is extremely important for strings, input/output, and low-level programming.
1️⃣ What is a Character Data Type?
A character data type (
char) stores one character at a time.
📌 Characters are stored internally as ASCII values
2️⃣ Size of char
✔ Always 1 byte (8 bits)
3️⃣ ASCII Value Concept ⭐
Each character has a numeric ASCII code.
| Character | ASCII |
|---|---|
| ‘A’ | 65 |
| ‘a’ | 97 |
| ‘0’ | 48 |
| ‘ ‘ (space) | 32 |
4️⃣ Types of char in C ⭐
C provides three variations of character type:
🔹 char
-
Can be signed or unsigned (compiler dependent)
🔹 signed char
Range: −128 to 127
🔹 unsigned char
Range: 0 to 255
5️⃣ Example: Signed vs Unsigned char
✔ Very important in embedded & system programming
6️⃣ Character Input & Output ⭐
Input
Output
7️⃣ Character Arithmetic 🔢
✔ Because characters are stored as numbers
8️⃣ char vs int (Important Difference)
| Feature | char |
int |
|---|---|---|
| Size | 1 byte | 4 bytes |
| Stores | Character / small number | Large number |
| ASCII usage | Yes | Indirect |
✔ char saves memory
9️⃣ char in Strings ⭐
📌 String = array of char
📌 Ends with '\0' (null character)
🔟 Special Characters in char
1️⃣1️⃣ char with <ctype.h> Functions 🔥
Common functions:
-
isalpha() -
isdigit() -
islower() -
toupper() -
tolower()
1️⃣2️⃣ Common Mistakes ❌
❌ Using double quotes "A" instead of 'A'
❌ Forgetting & in scanf()
❌ Assuming char is always signed
❌ Confusing '0' and 0
📌 Interview Questions (Must Prepare)
-
Size of
charin C? -
Difference between
charandunsigned char? -
What is ASCII?
-
Output of
char c = 65; printf("%c", c); -
Difference between
'A'and"A"?
🔥 Real-Life Use Cases
-
String processing
-
Text files
-
Keyboard input
-
Embedded systems
-
Byte-level operations
✅ Summary
✔ char stores a single character
✔ Always 1 byte
✔ Uses ASCII internally
✔ signed & unsigned affect range
✔ Essential for strings, I/O & system programming
