Comp 110 char - "Character"

char - "Character"

If you are using a single character value, you will use the type char.

What is a char?

  • A char is a type (more specifically, a textual type).
  • A char is essentially a character (ie. 'a', 'b', 'c', etc.)

Declaring and Initializing a char:

To declare and initialize a char, you will use the following syntax:

<type> <name> = <value>;

One thing to note about char is the syntax around the char itself. Similar to a String, a char does not stand alone; however, unlike String, it is encompassed by single quotes, not double quotations marks.

Examples:

char firstLetter = 'a';
char lastLetter = 'Z';
char exclamation = '!';
char strikes = '3';