C/C++ Arena

Step 5 of 6

Characters with char

A char holds a single character, written in single quotes: 'A'. Double quotes make a string, which is a different thing.

Print a char with %c:

char grade = 'B';
printf("Grade: %c\n", grade);

Under the hood a char is a small number (its ASCII code), so 'A' is 65. Printing a char with %d shows that number.

Your turn: write a program that stores the letter T in a char named team, then prints two lines:

Team: T
Code: 84

Previous: Decimals with double Next: Constants and sizeof