Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> C Language

Mastering Comments in C++: Best Practices & Syntax

Program comments are explanatory statements that you can include in the C++ code. These comments help anyone reading the source code. All programming languages allow for some form of comments.

C++ supports single-line and multi-line comments. All characters available inside any comment are ignored by C++ compiler.

C++ comments start with /* and end with */. For example −

/* This is a comment */

/* C++ comments can also
   * span multiple lines
*/

A comment can also start with //, extending to the end of the line. For example −

Live Demo
#include <iostream>
using namespace std;

main() {
   cout << "Hello World"; // prints Hello World
   
   return 0;
}

When the above code is compiled, it will ignore // prints Hello World and final executable will produce the following result −

Hello World

Within a /* and */ comment, // characters have no special meaning. Within a // comment, /* and */ have no special meaning. Thus, you can "nest" one kind of comment within the other kind. For example −

/* Comment out printing of Hello World:

cout << "Hello World"; // prints Hello World

*/

C Language

  1. Mastering C# Comments: Types, Best Practices, and XML Documentation
  2. Understanding C++ Type Conversion: Implicit, Explicit, and Casting Techniques
  3. Mastering C++ Operators: A Complete Guide with Practical Examples
  4. C++ Comments: Best Practices for Readable, Maintainable Code
  5. Mastering the C++ break Statement
  6. Mastering C++ Functions: From Basics to Advanced Usage
  7. Java Comments: Types, Usage, and Best Practices
  8. C++ Hello World Tutorial: Step‑by‑Step Code, Setup & Explanation
  9. Mastering Comments in C: Writing Clear, Effective Notes
  10. Understanding C++: Core Syntax and Object‑Oriented Foundations