Character Types
The char
data type is used to store a single character. The character must be surrounded by single quotes, like ‘A’ or ‘d’:
Example:
#include <iostream>
using namespace std;
int main () {
char myGrade = 'A';
cout << myGrade;
return 0;
}
//Output---> A
Alternatively, you can use ASCII values to display certain characters:
Example:
#include <iostream>
using namespace std;
int main () {
char a = 65, b = 66, c = 67, d = 68 ;
cout << a <<endl;
cout << b <<endl;
cout << c <<endl;
cout << d <<endl;
return 0;
}
Output—->
A
B
C
D
Tip: A list of all ASCII values can be found in our ASCII Table Reference.