Friday, July 29, 2016

C Basics - Comments in C

A "comment" is a sequence of characters beginning with a forward slash/asterisk combination (/*) that is treated as a single white-space character by the compiler and is otherwise ignored.

A comment can include any combination of characters from the representable character set, including newline characters, but excluding the "end comment" delimiter (*/). Comments can occupy more than one line but cannot be nested. You cannot include comments within tokens.

Comments are used to mention the purpose of the statement. Comments are not necessary. Any number of comments can be written at any place in the program. It improves the readability of the code. Note that the compiler treats comments as white space character.

Use comments to document your code. This example is a comment accepted by the compiler:
/* Comments can contain keywords or reserved words such as for and while without generating errors. */

Comments can appear on the same line as a code statement:
printf( "Hello\n" ); /* Comments can go here */

You can choose to precede functions or program modules with a descriptive comment block:
/* HELLO.C illustrates sample hello world program * for c language begineers. */

Since comments cannot contain nested comments, this example causes an error:
/* Comment out this routine for testing /* Open file */ */



Related topics:
Tokens in C   |   Character Set in C   |   White Space Characters in C   |   Trigraph Characters in C   |   Extended Characters in C   |   Escape Sequence in C   |   Keywords in C   |   Identifiers in C   |   Declaration in C

List of topics: C Programming

No comments:

Post a Comment