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

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

1 year ago