Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE

C Character Data Types


The char Type

The char data type is used to store a single character.

The character must be surrounded by single quotes, like 'A' or 'c', and we use the %c format specifier to print it:

Example

char myGrade = 'A';
printf("%c", myGrade);
Try it Yourself »

Alternatively, if you are familiar with ASCII, you can use ASCII values to display certain characters. Note that these values are not surrounded by quotes (''), as they are numbers:

Example

char a = 65, b = 66, c = 67;
printf("%c", a);
printf("%c", b);
printf("%c", c);
Try it Yourself »

Tip: A list of all ASCII values can be found in our ASCII Table Reference.


Notes on Characters

If you try to store more than a single character, it will only print the last character:

Example

char myText = 'Hello';
printf("%c", myText);
Try it Yourself »

Note: Don't use the char type for storing multiple characters, as it may produce errors.

To store multiple characters (or whole words), use strings (which you will learn more about in a later chapter):

Example

char myText[] = "Hello";
printf("%s", myText);
Try it Yourself »

For now, just know that we use strings for storing multiple characters/text, and the char type for single characters.