CPP Character Data Type

💻 CPP Character Data Type (char) – Complete Beginner to Interview Guide
In CPP Character Data Type is used to store a single character, such as letters, digits, or symbols.
1️⃣ What is Character Data Type? ⭐
In C++, the char data type stores one character at a time.
Example
📌 Characters are always written inside single quotes ' '.
2️⃣ Declaring a Character Variable ⭐
Syntax
Example
3️⃣ Character Data Type Example ⭐
Output
4️⃣ Character Input Using cin ⭐
Input
Output
📌 cin reads only one character.
5️⃣ Size of char Data Type ⭐
📌 Size: 1 byte
6️⃣ ASCII Value of Characters ⭐⭐
Each character has an ASCII value.
Output
📌
'A'→ 65'a'→ 97'0'→ 48
7️⃣ Character Arithmetic ⭐⭐
Output
📌 Character arithmetic works using ASCII values.
8️⃣ char vs string ⭐⭐
char | string |
|---|---|
| Stores single character | Stores multiple characters |
Uses ' ' | Uses " " |
| Size = 1 byte | Variable size |
Example
9️⃣ Special Character Constants ⭐⭐
📌 These are called escape characters.
🔟 Common Character Errors ❌
❌ Using double quotes "A" instead of 'A'
❌ Storing multiple characters in char
❌ Forgetting ASCII conversion
❌ Confusing char with string
📌 Interview Questions (C++ Character Data Type)
Q1. What is the size of char in C++?
👉 1 byte
Q2. Difference between 'A' and "A"?
👉 'A' is char, "A" is string
Q3. Can char store numbers?
👉 Yes, as characters ('1', '2')
Q4. What is ASCII?
👉 Numeric representation of characters
✅ Summary
✔ char stores single character
✔ Uses single quotes ' '
✔ Size is 1 byte
✔ Characters have ASCII values
✔ Used in input, conditions & logic
