Categories: C

Comments in C

Comments in C are an explanation or description of the source code of the program. It helps a developer explain the logic of the code and improves program readability.  These comments are not executed by the compiler rather ignored by it.

Type of comments:

There are two types of comments in the C language.

  • Single-Line Comments
  • Multi-Line Comments

Single line Comment:

  • Single line comments are represented by // double slash.
  • It denotes only a single line that gets commented.
  • Syntax:
//code to be commented

Multi-line Comment:

  • Multi-line comments are represented by /*……*/ i.e., start with forwarding slash and asterisk (/*) and end with asterisk and forward-slash (*/)
  • It denotes multiple lines that get commented.
  • Syntax:
/*  
code 
.....
.....
.....
to be commented 
*/  
Example:
#include<stdio.h>    
int main(){    
    /*Start of main()
      Program to print hello coderzpy
      Multi-Line Comment*/  
    printf("Hello Coderzpy !"); 
   
    return 0;  
   //end of main()
}    
OUTPUT: Hello Coderzpy !

In the above code /*printing information Multi-Line Comment*/ is the multi line comment whearas, //end of main() is single line comment.

Need for Comments :

  • A person reading a large code will be confused if comments are not present about the details of the program.
  • A comment makes a code more readable by providing more description.
  • They can include a description of an algorithm to make code coherent.
  • Comments can be helpful for our code if it is reused after a long interval.

note: also read about Variables & Constants in C & Precedence of Operators in C.

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

1 month ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

2 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

2 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

3 months ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

3 months ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

3 months ago