Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

C++ Program Structure · Lesson 9 of 25

Functions

A free lesson from Swipe Coding · C++, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Functions are how C++ programs stay organized instead of turning into one giant mess. 🧱

A C++ program is built out of "functions" — named, reusable blocks of code that perform a specific task. Instead of writing the same instructions over and over, you can define a function once and then "call" it wherever you need that task done.

int addNumbers(int a, int b) {
    return a + b;
}
A function named "addNumbers" that takes two whole numbers and returns their sum.

Every function has a few key parts: a return type (what kind of value it hands back, such as "int" for a whole number, or "void" for nothing at all), a name, a list of parameters in parentheses (the inputs it accepts), and a body in curly braces { } containing the statements it runs.

Quick check

What is a function in C++?

🤖
The word 'void' shows up a lot — it just means 'nothing to hand back'. 📭

A function that does not return any value uses the return type "void". For example, a function whose entire job is to print something to the screen usually returns "void", since it doesn't need to hand any value back to whoever called it.

void greet() {
    std::cout << "Hello there!";
}
This function prints a greeting and returns nothing, so its return type is "void".
Fill in the blank

A function that does not return any value uses the return type ____.

True or false

A function can be reused by calling it multiple times, instead of rewriting its code each time.

🤖
One very special function is coming up next — every C++ program needs it. ➡️

Every C++ program is a collection of one or more functions. But there is exactly one function that every single C++ program must have — the one where the program actually begins running. That function is called main(), and it's the subject of the next lesson.

Keep your streak going in Swipe Coding

Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →