Comments in programming languages are used to document the programs. Comments are non-executable and are used to explain the code written in the program.
Different programming languages have different syntaxes for writing the comments in the program. Let’s have a look at a few of them.
There are two ways to comment in C+, Javascript, JAVA, and PHP:
//
/*
In single-line commenting, the text starting with //
to the end of the line is ignored by the compiler and not executed.
In multiline commenting, the code between /*
and */
is considered as comments and not executed.
#include <iostream>using namespace std;int main() {// This is the comment and is ignored by the compiler.cout << "This line is executed by the compiler." << endl;/*thisismultilinecomment*/cout << "After the comments this code is executed.";return 0;}
There are two ways to comment in Python, Ruby, and R:
#
print "Hello World"# this is single line comments
Note: R does not support multi-line comments.
Multi-line comments for Python and Ruby are given below:
print "Hello World""""this is theway to writemultiline comment in python"""
Free Resources