Char
Part of the Fundamentals section of Coddy's C++ journey — lesson 9 of 74.
A char is a single character (For example: 1, 6, %, b, p, ., T, etc.)
The char type is a special type that consists of a single character.
To initialize a char value in a variable, enclose it within single quotation marks:
char c1 = 'h';In the above example, a char variable named c1 is initialized.
Challenge
BeginnerStore the char B in a variable named initial.
Cheat sheet
A char is a single character data type that stores one character (letters, digits, symbols, etc.).
To declare a char variable, use single quotation marks:
char c1 = 'h';Try it yourself
#include <iostream>
int main() {
// Type your code below
char initial = ?
// Don't change the line below
std::cout << "initial = '" << initial << "'";
return 0;
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else