C++ Comments In Depth

C++ comments are the explanatory statement or the statements that define our code to someone who is reading our code and it makes the code easily understandable by everyone. Comments are used in every programming language. Comments are considered as a good practice.

C++ Comments In Depth

In this tutorial we will learn about comments in C++, We will learn why and when we use comments in any programming language. Before moving on to C++ Comments let's just see what comments simply mean then we will learn about C++ comments and its types.

A comment is basically a line that defines or reminds something about our content.

In computer programming, a comment is a line of code that explains the source code of a computer program more easily and efficiently. It basically makes our program more human-readable. Comments are neglected by the compilers and interpreters during the program run.

There are two ways that we can use to insert comments in the C++ programs:

Single-Line Comments ( // ) -The comments that begins with // are single line comments in C++. The C++ compiler ignores everything following // in that same line.

Example:

// My first comment in C++ 

What if we wanted to arrange our comment in multiple lines in the C++ program then we use multi-line comments in C++.

Multi-Line Comments (/*....*/) - It starts with /* and ends with */. So everything inside the starting tag and end tag is considered as comment. It can be written in multiple lines.

Example:

/* This is my first comment in C++
    Best of luck for your future */

Note: All the comments in every compiler are highlighted with some different colors.

So basically there are two types of comments in C++.

  1. Single-Line Comment (//) 
  2. Multi-Line Comments (Block comment).

Let us just stop here in this tutorial we will look more concepts in other tutorials. So please be with us for the journey of learning C++.

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0