Comments in C language | types of Comments delimiter with examples


Comments in C language | types of Comments delimiter with examples

What is a Comments in C language?

Comments are used to describe or indicate or comments the large block of text or fragments of code or the nearest codes and syntaxes for programmer (comment is readable explanations of code for programmers). Comments have words or single sentence or single paragraph but, it does not change the meaning of program or nearest code. Compiler treats like meaningless or Blank

Comment provides clarity of the C program source code which allow the programmer to understand the intend of lines of codes. 

Comments are very important because comments help the programmers to understand if debug in found in program which contains thousand of lines of codes.

In C language, There are two syntaxes which are use to give the comments before or after code or block of texts.

Comments using Preprocessor directives:

it is typically use to make easy the sources of programs and also make easy to compile in different level of execution environments. Directives of source codes file declare the preprocessor to specific action. 

Like: preprocessor can be change the place of Tokens present in the TextInsert the contents of other files into the source file. Statements of Preprocessor are use the same set of characters as source file statements, same as the execution and also recognizes negative characters values and escape sequence which are not supported. 

The preprocessor recognizes the some following directives which are given below:

Number sign(#) must be first before characters without white-space in line which contains directive. Only white-space character can exist between number sign and first character of directive. But, some directive includes the arguments or values. Any block of text which follow directive (excepts argument and variable that are part of the directive) and followed by single-line comment delimiter (//) and multi-line comment delimiter (/*  */). 

  • #define
  • #elif
  • #else
  • #endif
  • #error
  • #if
  • #ifdef
  • #ifndef
  • #import
  • #include
  • #line
  • #pragma
  • #undef
  • #using
#if 0
/* You can start comments from here */
/* this delimiter is use for multiple line */
//this delimiter is use for single line
#endif

There are two types of Comments in C language:

/*  */ delimiter comments for multiple-line:

These comments starts with a forward slash and asterisk (/*) and also end with same asterisk and slash (*/). You may know that it is executed as blank( means ignored by C compiler). 

/* delimiter is use to comment for multiple-line.
Means you can use this delimiter for paragraph,
Large or long block of text with multi-line */

/* printf("%d is a real number", num);
printf("%d is not a real number", num); */

// delimiter comments for single-line:

This delimiter comments is start with double-forward slash (//). Same point, started by (//) delimiter is executed as blank or ignored by C compiler. It is modern comment delimiter in C language. 

//this delimiter is use for single-line comments.
//it's mean that only use single line or words or
// block of text but  arranged in single-line without press 'Enter key'.

//printf("%d is a real number", num);

How to comments Single-line comments in C language?

By using (//) delimiter you can comments single-line comments (block of text, fragments of codes) in your C program code. Start writing comments or make single-line comments followed by 'double' forward slash(//).
Examples-  // blocks of text.
                    //fragments of codes.
                   //sentences with single-line.

How to comments Multiple-lines or paragraph comments in C language?

By using (/*  */) delimiter you can comments multiple-line comments(blocks of large or long text, paragraph block of code) in your C programs code. Start writing comments or make multiple-line comments followed by forward slash and asterisk (/*) and end with (*/).
Example- /* you can write paragraphs or                         long block of text in your C                                 program. Even block of code, if                         code give error. */
               /* C functions or block of functions*/

Why we use Comments in C language Programe? 

As per upper guidance, comment is readable explanations of code in C program. It is use to explain the theme of nearest code. In future, if any types of bug or error is found in that case, comment make easy to understand the block of code or  make comments of block of code which give error in software or in compiler. 

Post a Comment

0 Comments