Comments in C++

Comments are the non executable statements in the source code. These statements are added in between source code to explain the purpose of code. It is most commonly used as quick documentation of source code.

Types of Comments

There are two types of comments in C++.

1. Single Line Comments

Single line comments are start with double slash operator ( // ). The entire line is treated as comment until enter is press. When enter key is press this is considered as end of single line comment.

Example of Single Line Comment

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	
	int a;  // variable a is used to store age of user.
	char g; // variable c is used to store grade of user.
	
	return 0;
}

1. Multi Line Comments

Multi line comments are starts with /* and end with */. The entire text including lines is treated as comment in source code. This type of comment is used when there is required to add more than one lines as comment.

Example of Multi Line Comment

#include <iostream>
using namespace std;

/* This Multi-line comment
   example is provided by
   Institute Management System.
*/

int main(int argc, char** argv) {
	
	cout<<"Hello World";
	
	return 0;
}

 

Comments
Login to TRACK of Comments.