Course contentsShow
← Computer Science
Lesson 143 of 2,8724. Introduction to ProgrammingFree lesson

Character Data Type

Storing and manipulating single characters using the char type.

Character Data Type

You'll learn how to store and work with single letters, symbols, and digits using the char data type.

What Is a Character?

In programming, a character is any single symbol you can type: a letter ('A', 'z'), a digit ('7'), punctuation ('!', '?'), or even a space (' '). Unlike strings (sequences of characters), the char type holds exactly one character at a time.

Think of a character variable as a labeled box that can hold one letter tile from a Scrabble set—just one tile, no more, no less.

Declaring and Using Character Variables

When you declare a char variable, you're creating a container specifically sized for one character. In many languages, you wrap the character in single quotes to distinguish it from other data types:

char initial = 'J'
char grade = 'A'
char symbol = '$'

Notice how each variable holds exactly one character. The single quotes tell the computer "this is a character, not a word or number."

Why Characters Matter

Characters are the building blocks of text processing. Every letter you type, every key you press, gets represented as a character. Under the hood, computers store characters as small integer codes (like ASCII or Unicode values), but you can work with them as readable symbols.

You can compare characters, change them, or use them to build larger text structures later in your programming journey.

Key Takeaway: The char data type stores a single character enclosed in single quotes, serving as the fundamental unit for representing text in programs.