Multi-Line Comment
A multi-line comment can occupy many lines of code, it starts with /* and ends with */, but it cannot be nested. Any text between /* and */ will be ignored by the compiler.
Syntax:
/* Multiline Comment . . . */
Example:
C++
// C++ Program to demonstrate Multi line comment #include <iostream> using namespace std; int main() { /* Multi line comment which will be ignored by the compiler */ cout << "GFG!" ; return 0; } |
Output
GFG!
Tip: Some IDEs provide shortcut to apply comments as well, such as:
- Shortcut for single line: The shortcut to make a single line into a comment is ‘ctrl + /’.
- Shortcut for multi-line: To make a multiline comment, we can select all the lines we want to comment out and then use the same shortcut (‘ctrl + /’).
C++ Comments
Comments in C++ are meant to explain the code as well as to make it more readable. When testing alternative code, it can also be used to prevent execution. The purpose of the comments is to provide information about code lines. Programmers commonly use comments to document their work.
Contact Us