2.3. Comments

C++ supports two comment formats. The first is a one-line format.

// this is a comment line 

The compiler treats all text following the double slashes as a comment, which may appear on a line by itself or follow a C++ statement. Once you begin a comment with //, the compiler terminates the comment with a newline. We've been using one-line comments all along, but here are some more examples.

// define a circle 
const double pi = 3.14159;          // constant value pi
double radius = 2.5;                // radius of a circle
double area;                        // area of a circle
double circum;                      // circumference of a circle

area = pi * radius * radius;        // calculate area
circum = 2 * pi * radius;           // calculate circumference

// double volume;                   // circles don't have volumes

Note that ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.