C++ Comments

Christine_Yang's avatar
Published May 6, 2021Updated Dec 21, 2022
Contribute to Docs

A comment is a piece of text within a program that is not executed. It can be used to provide additional information to aid in understanding the code.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Single-line Comments

Single-line comments are created using two consecutive forward slashes. The compiler ignores any text after // on the same line.

// This line will denote a comment in C++

Multi-line Comments

Multi-line comments are created using /* to begin the comment, and */ to end the comment. The compiler ignores any text in between.

/*
This is all commented out.
None of it is going to run!
*/

Codebyte Example

Here’s a program with a multi-line comment and two single-line comments:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours