Small Steps I — Creating with Text and Numbers

Storing strings too

Store your favorite food's name in food and print it after Food:.

What you will learn

You can store names and sentences in variables too. A string is a kind of value; String is the name of the Small type used to store it.

Try it

Example · example.cpp
void small_main()
{
    String name = "Alex";
    print("Hello, ", name);
}

print("Hello, ", name); prints the greeting followed by the value of name. It does not print the comma or automatically add a space. Put any spaces you need inside the double quotes.

"123" is a string of characters. It is a different kind of value from the integer 123 used in numeric calculations.

Expected output:

Hello, Alex

Exercise

Store your favorite food's name in food and print it after Food:.

Exercise starter · exercise_starter.cpp
void small_main()
{
    String name = "Alex";
    print("Hello, ", name);
}

Hint

Change the parts of the example that you need.

show solution
void small_main()
{
    String food = "Pizza";
    print("Food: ", food);
}
← Previous lessonNext lesson →