Writing C++ Comments
Writing C++ Comments
Writing C++ Comments
comments
John Osige
•Adding Comments in a program
•C++ introduces a new comment symbol “//”(double slash). Comments start with a double slash
symbol and terminate at the end of the line. A comment may start anywhere in the line. The double
slash comment is basically a single line comment.
•Ex: //this is an example
•The C comment symbols “/* , */are still valid and are more suitable for multiline comments.
•Ex: /*this is an example of
•C++ program */.
•Linking Section:
•The linking section contains two parts:
•Header Files:
Generally, a program includes various programming elements like built-in functions,
classes, keywords, constants, operators, etc. that are already defined in the standard
C++ library.
In order to use such pre-defined elements in a program, an appropriate header must
be included in the program.
Standard headers are specified in a program through the
preprocessor directive #include. In Figure, the iostream header is used. When the
compiler processes the instruction #include<iostream>, it includes the contents of the
stream in the program. This enables the programmer to use standard input, output,
and error facilities that are provided only through the standard streams defined in
<iostream>. These standard streams process data as a stream of characters, that is,
data is read and displayed in a continuous flow. The standard streams defined in
<iostream> are listed here.
•Namespaces:
A namespace permits grouping of various entities like classes, objects, functions, and various C++ tokens, etc. under
a single name.
Any user can create separate namespaces of its own and can use them in any other program.
In the below snippets, namespace std contains declarations for cout, cin, endl, etc. statements.