Char
Part of the Fundamentals section of Coddy's Rust journey — lesson 6 of 75.
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:
let c1: char = 'h';In the above example, a char variable named c1 is initialized.
Challenge
BeginnerStore the char C in a variable named initial.
Cheat sheet
A char is a single character data type that stores one character (letters, numbers, symbols, etc.).
To declare a char variable, use single quotation marks:
let c1: char = 'h';Try it yourself
fn main() {
// Type your code below
let initial: char = ?;
// Don't change the line below
println!("initial = '{}'", initial);
}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 OperatorArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 33Variables Part 2
Type DeclarationNaming ConventionsType InferenceRecap - Initialize VariablesType Casting9Loops
For Over SeriesWhile LoopBreakContinueNested LoopLoop LabelsInfinite LoopRecap - Dynamic Input