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

Longest Absolute Path in File System Representation

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

4 days ago

Efficient Order Log Storage

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

2 weeks ago

Select a Random Element from a Stream

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

3 weeks ago

Estimate π Using Monte Carlo Method

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

1 month ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

1 month ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

1 month ago