Comments in C++


Advertisements

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 −

#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

*/

Useful Video Courses


Video

C++ Online Training

154 Lectures 11.5 hours

Arnab Chakraborty

Video

Learn C++ Pointers with Visual Studio 2017

14 Lectures 57 mins

Kaushik Roy Chowdhury

Video

Modern OpenGL C++ 3D Game & 3D Rendering

30 Lectures 12.5 hours

Frahaan Hussain

Video

Cocos2d-x v3 C++ - Beginning Game Development

54 Lectures 3.5 hours

Frahaan Hussain

Video

C++ Development - The Complete Coding Guide

77 Lectures 5.5 hours

Frahaan Hussain

Video

Tic-Tac-Toe Clone - The Complete Cocos2d-x C++ Game Course

12 Lectures 3.5 hours

Frahaan Hussain

Advertisements