Small Steps I — Creating with Text and Numbers

Giving a value a name

Store 10 in an int variable named age and print it.

What you will learn

A variable is a named place to store a value. Let us remember a score under the name score.

Try it

Example · example.cpp
void small_main()
{
    int score = 10;
    print(score);
}

int score = 10; creates a variable named score and gives it the initial value 10. int is an integer type. A type describes the kind of value stored; integers such as 0, 10, and -3 have no fractional part.

Creating a variable is called declaration; giving it its first value is initialization. For now, always give a variable a value when you create it. print(score); prints the stored value, rather than the letters score.

Expected output:

10

Exercise

Store 10 in an int variable named age and print it.

Exercise starter · exercise_starter.cpp
void small_main()
{
    int score = 10;
    print(score);
}

Hint

Use the name age instead of score.

show solution
void small_main()
{
    int age = 10;
    print(age);
}
← Previous lessonNext lesson →