Comments

In programming, often more than one person works on a project. You can probably imagine that code worked on by hundreds of people can be chaotic. For this reason, comments exist in almost all programming languages.

Comments mark a part of the program that the computer will ignore.

In C++ we have two types of comments:

1. Single-line comments, which start with two slashes //:

// This is a single-line comment
std::cout << "Hello" << std::endl; // This comment is at the end of the line

2. Multi-line comments, which start with /* and end with */:

/* 
Author: Roman Látal
Date: December 22, 2024
*/

std::cout << "Hello" << std::endl;

Comments are useful for:

  • Explaining more complex parts of code
  • Temporarily disabling parts of code during testing
  • Documenting functions and their parameters
  • Notes for other programmers (or for yourself in the future)

Instructions

Add any comment to the code

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

4/5

Comments | Start Coder