Comments are user-defined remarks inserted into code to give the reader more information than is provided by the code alone. Comments are ignored by compilers.
In C (and C++) there are two types of comment: single-line comments and multi-line comments. A single line comment begins with a double-slash (\\) and extends to the end of the line. A multi-line comment starts with a slash-asterisk (\*) and extends to the first occurrence of an asterisk-slash (*/). Multi-line comments need not extend across multiple lines, they can also be used to insert comments inside code on a single line.
Note that outside of tutorial code, comments should never just repeat what the code does; the code itself tells you what it does, but it may not be clear why it is doing it. Comments should be brief and informative but should not distract the reader with any unnecessary detail.
Comments are non-code segments; notes that a programmer inserts into their source code to act as a reminder, both to themselves and to others, of exactly why a particular section of code exists.
While it may be obvious why a code section exists while we're actually writing it, after a few days or weeks have passed that logic may not be quite so clear cut. By explaining the logic as we go, we save ourselves the pain of re-working the logic.
Many novice programmers only use comments to explain whata code section does -- often commenting every single line. While this is fine for trivial programs to aid in the learning process, to better explain the fundamentals of the language, a competent programmer already knows what the code does simply by reading the code itself. Well-written code should always be easy to read and understand without the need for a comment to repeat the fact. But the logic is rarely as obvious, especially if the code was written by another programmer.
Comments in C are delimited by /* and */ tokens and can extend over multiple lines. Comments in C++ can also use C-style tokens, or they can use the new // token. The // token signifies to the compiler that the remainder of the line on which it appears is a comment. A code segment may precede a /* or a // token on the same line.
Examples:
/* This is a single-line C-style comment */
/* This is a multi-line
a C-style comment */
// This is a single line C++ comment.
/*********************************
This is a c-style introduction "banner".
We use these to separate one major code
segment from another, or to more fully
document the logic behind the code that
follows.
*********************************/
/////////////////////////////////////////////////////
// This is a C++ introduction banner.
//
// We use these to separate one major code
// segment from another, or to more fully
// document the logic behind the code that
// follows.
/////////////////////////////////////////////////////
Comments, are small definitions that a programmer inserts into their source code, it gives an indication as to what that specific piece of code does.
It also helps other programmers, to know what a section does, this is a time saver for everyone involved.
Comments in C is done by starting with the "//" and ending with the ://".
Everything written in between those sections are disregarded when the program is being executed (ran).
/* they are supposed to help a human reader to understand what the program does, or how it does it */
the main() function,the#include Directive, the variable definition. function prototype, program statements, the function definition,program comments and braces are the components of program in C++
/* my second program in C++ with more comments */ #include <iostream> using namespace std; int main () { cout << "Hello World! "; // prints Hello World! cout << "I'm a C++ program"; // prints I'm a C++ program return 0; }
COMMENT:- comment a re not necessary in the program. however, to understand the flow of programs the programmer can include comments in the program. comment are to be inserted by the programmer. It is useful for documentation.Comment are nothing but some kind of statements which are placed between the delimiters /* & */. The compiler does not execute comments. Thus, we can say that comments are not the part of executable program.The user can frequently use any number of comments that can be placed any where in the program. Please note that the comments and statements can be nested. The user should select the OPTION MENU of the editor and select the COMPILER - SOURCE -NESTED COMMENTS ON/OFF). The Comments can be inserted with a single statement or in nested statement.Types of comment in c/c++. is following bellow1. // this is a single line comment2. /* */ this sing is multi line OR nested line commentseg. /* int i=90;char ch=65; */ close multi line commentsmade by [ARUN KUMAR RAI]
comments
if single line comment just place // before for single line comment else if multiple line denote as like this /*............................. ..............................*/ Strictly speaking, // is non.standard in C only in C++
There are no comments in C programs. Comments only exist in the source code and the precompiler automatically strips them out before the compiler sees them.
C++ also supports C program's multiple command line /* your command */.
the main() function,the#include Directive, the variable definition. function prototype, program statements, the function definition,program comments and braces are the components of program in C++
'cos' they are just comments.
/* my second program in C++ with more comments */ #include <iostream> using namespace std; int main () { cout << "Hello World! "; // prints Hello World! cout << "I'm a C++ program"; // prints I'm a C++ program return 0; }
Please visit http://talentsealed.blogspot.com/2009/10/to-display-triangle-using-c-programming.html for the answer. Please let me know your comments
The comments are there to (a) aid in debugging the program, (b) help the programmer layout the program in logical steps and (c) show anyone else looking at the code to see what each section of the code actually does.
COMMENT:- comment a re not necessary in the program. however, to understand the flow of programs the programmer can include comments in the program. comment are to be inserted by the programmer. It is useful for documentation.Comment are nothing but some kind of statements which are placed between the delimiters /* & */. The compiler does not execute comments. Thus, we can say that comments are not the part of executable program.The user can frequently use any number of comments that can be placed any where in the program. Please note that the comments and statements can be nested. The user should select the OPTION MENU of the editor and select the COMPILER - SOURCE -NESTED COMMENTS ON/OFF). The Comments can be inserted with a single statement or in nested statement.Types of comment in c/c++. is following bellow1. // this is a single line comment2. /* */ this sing is multi line OR nested line commentseg. /* int i=90;char ch=65; */ close multi line commentsmade by [ARUN KUMAR RAI]
comments
Comments P.64 - Bottom of page
Comments
Comments are to help other programmers (or yourself in the future) to understand what is going on in a program, especially when the code itself is complicated and may not be obvious. More time is spent maintaining and improving programs than original development, so leaving clear comments is very important!