Comments in C++ Programming

Comments in C++ Programming
Comments in C++ Programming

Comments in C++: A comments can be used are programmer readable notes in the source code of a C++ program used to make the program easier to read and understand. Comments are not executed by the compiler or an interpreter. It is most important part of programming because it is very understandable or easy to use comments.

comments are used by programmers to add explain notes and documentation within the source code. They are ignored by the compiler and do not affect the program's execution or performance.


Types of Comments in C++

1. Single Line Comments

2. Multiline Comments


Single Line Comments in C++

A Single line comments can be used to comment in a single line of code. Single line comments can be start with two forward slashes (//). Single line everything after the double slashes on that line is considered a comment.

Example of Single Line Comments in C++

#include<iostream>
using namespace std;
int main(){
int x=100;
int y=200;
//This is a addition of two numbers.
//This is a Single Line Comments
int add=x+y;
cout<<"Addition of x+y:"<<add;
}
============OUTPUT============
Addition of x+y:300


Multiline Comments in C++

A Multiline comments can be used to write comments that span more than one line. Multiline comments are generally used for multiple line or descriptions. Multiline comments are start with /* and end with */. It is a considered every line comments.

Example of Multiline Comments in C++

#include<iostream>
using namespace std;
int main(){
/* This program of multiple of two values.
This is a Multiline comments.*/
int x=100;
int y=5;
int multi=x*y;
cout<<"Multiple of x*y:"<<multi;
}
============OUTPUT============
Multiple of x*y:500

Advantages of Comments in C++

Comments Purpose: Comments is a improve source code readability, maintainability, and help with collaboration and debugging large program.


Ignored Comments Compiler: The C++ compiler treats comments as whitespace and removes them during the compilation process. Comments are not effect our actual source code. Comments are only used understand notes line.


Conclusion of Comments in C++

Conclusion: A comment can be used ignore the line of code. It can be used readable program notes. A comment source code are not execute in our C++ program.


Post a Comment

0 Comments