CPP Character Data Type

C++ Tutorial

💻 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

char grade = 'A';

📌 Characters are always written inside single quotes ' '.


2️⃣ Declaring a Character Variable ⭐

Syntax

char variable_name;

Example

char ch = 'X';

3️⃣ Character Data Type Example ⭐


 

Output

B

4️⃣ Character Input Using cin


Input

A

Output

A

📌 cin reads only one character.


5️⃣ Size of char Data Type ⭐

cout << sizeof(char);

📌 Size: 1 byte


6️⃣ ASCII Value of Characters ⭐⭐

Each character has an ASCII value.


Output

A
65

📌

  • 'A' → 65

  • 'a' → 97

  • '0' → 48


7️⃣ Character Arithmetic ⭐⭐


Output

B

📌 Character arithmetic works using ASCII values.


8️⃣ char vs string ⭐⭐

charstring
Stores single characterStores multiple characters
Uses ' 'Uses " "
Size = 1 byteVariable 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

You may also like...