Small Steps I — Creating with Text and Numbers

Passing values to a function

Pass 7 and 10 to show_double and print the results in order.

What you will learn

Passing a value lets a function do the same work with different values. A variable that holds a received value is a parameter.

Try it

Example · example.cpp
void show_double(int number)
{
    print(number * 2);
}

void small_main()
{
    show_double(3);
    show_double(5);
}

number starts at 3 in the first call and 5 in the second. The values 3 and 5 supplied in the calls are arguments. number is a variable used while this function runs.

Expected output:

6
10

Exercise

Pass 7 and 10 to show_double and print the results in order.

Exercise starter · exercise_starter.cpp
void show_double(int number)
{
    print(number * 2);
}

void small_main()
{
    show_double(3);
    show_double(5);
}

Hint

Change the parts of the example that you need.

show solution
void show_double(int number)
{
    print(number * 2);
}

void small_main()
{
    show_double(7);
    show_double(10);
}
← Previous lessonNext lesson →