Object-Oriented Programming (OOP)

4. Introduction to Data Types

4.3. Character

A character represents a single symbol, such as a letter, digit, or punctuation mark, typically stored as a numeric code (e.g., ASCII or Unicode).

Characteristics

Storage: 1 byte for ASCII (e.g., C), 2 bytes for Unicode in Java (char).

Range: ASCII (0–127 for basic characters), Unicode (wider range for global scripts).

Operations: Comparison, concatenation (when used in strings), or conversion to numeric codes.

Use Cases

Storing single letters or symbols (e.g., 'A', '#').

Building blocks for strings.

Encoding special characters in text processing.

Examples

Python: c = 'A' (Python treats single characters as strings)

Java: char c = 'A';

C++: char c = 'A';

Notes

Python has no distinct char type; single characters are strings of length 1.

Java’s char is 16-bit Unicode, supporting international characters.