C Character Data Types

R Tutorial

🔤 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.

char ch = 'A';

📌 Characters are stored internally as ASCII values


2️⃣ Size of char

printf("%lu", sizeof(char)); // 1 byte

✔ Always 1 byte (8 bits)


3️⃣ ASCII Value Concept ⭐

Each character has a numeric ASCII code.

char ch = 'A';
printf("%d", ch); // 65
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

signed char a = -100;

Range: −128 to 127

🔹 unsigned char

unsigned char b = 200;

Range: 0 to 255


5️⃣ Example: Signed vs Unsigned char


 

✔ Very important in embedded & system programming


6️⃣ Character Input & Output ⭐

Input


⚠️ To skip whitespace:

scanf(" %c", &ch);

Output

printf("%c", ch);

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 ⭐

char name[] = "C Language";

📌 String = array of char
📌 Ends with '\0' (null character)


🔟 Special Characters in char


✔ Used in formatting & string termination


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)

  1. Size of char in C?

  2. Difference between char and unsigned char?

  3. What is ASCII?

  4. Output of char c = 65; printf("%c", c);

  5. 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

You may also like...