Small Steps I — Creating with Text and Numbers
Taking out one character
Print m, the second character of Small.
What you will learn
A character is a single letter or symbol. char is a type for character values. Write one English letter with single quotes, such as 'A'.
Try it
Example · example.cpp
void small_main()
{
char grade = 'A';
print(grade);
String word = "Small";
print(word[0]);
}
word[0] reads the character at the first position. Positions start at 0. The valid positions in Small are 0 through 4.
7 is an integer, '7' a character, and "7" a string. char holds one byte, so a whole Korean UTF-8 character cannot fit in one char. Practice with English letters here.
Expected output:
A
S
Exercise
Print m, the second character of Small.
Exercise starter · exercise_starter.cpp
void small_main()
{
char grade = 'A';
print(grade);
String word = "Small";
print(word[0]);
}
Hint
The second position has index 1.
show solution
void small_main()
{
String word = "Small";
print(word[1]);
}