Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Comments · Lesson 19 of 25

Multi-Line Comments

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

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

🤖
Sometimes one line just is not enough room to explain yourself. 📄

Sometimes a single line isn't enough to explain something. For longer comments, C++ has a second notation: the multi-line comment. It begins with /* and ends with */ — everything in between is ignored, no matter how many lines it spans.

/* This is a
   multi-line comment
   that spans three lines. */
std::cout << "Hello!" << std::endl;
Everything between /* and */ is ignored by the compiler — even across multiple lines.
🤖
This style is perfect for describing a whole file right at the top. 🗂️

Multi-line comments are especially well-suited for longer explanations — for example, to describe at the beginning of a file what a program actually does.

/*
 * This program greets the user.
 * It is for practice purposes only.
 */
#include <iostream>

int main() {
    std::cout << "Hello!" << std::endl;
    return 0;
}
The asterisks (*) at the start of each line are just a visual convention many C++ programmers follow. For the compiler, all that matters is that everything sits between /* and */.
Fill in the blank

A multi-line comment in C++ begins with /* and ends with ____.

Another practical use: with /* */ you can "turn off" multiple lines of code at once, without having to write // in front of every single line.

int main() {
    std::cout << "Start" << std::endl;
    /*
    std::cout << "Middle 1" << std::endl;
    std::cout << "Middle 2" << std::endl;
    */
    std::cout << "End" << std::endl;
    return 0;
}
Both "Middle" lines are completely skipped — only "Start" and "End" are actually printed.
Quick check

What does this program print?

int main() {
    std::cout << "Start" << std::endl;
    /*
    std::cout << "Middle 1" << std::endl;
    std::cout << "Middle 2" << std::endl;
    */
    std::cout << "End" << std::endl;
    return 0;
}
🤖
Forgetting to close this one causes a very confusing kind of bug. ⚠️

An important difference from //: a multi-line comment always has to be closed with */. If you forget it, the compiler treats all the remaining code up to the next */ it finds as a comment — which can silently swallow real code and lead to very confusing errors.

True or false

A multi-line comment /* ... */ can span multiple lines.

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 →