Tutorials

C Basics


C Comments


We have already heard about comments while discussing basic structure of C programming in this tutorial.

Here we are going to learn in detail about comments in C programming

 

We have two types of Comment in C:

  1. Single line comment
  2. Multi line comment

Single line comment

A single line comment can be added by using two forward slash (//).

If you give any single line comment in program then you can use   forward slash (//) up to the end of line is ignored by the compiler.

 

Example

This is how you can give a single line comment in C programming

//first c program….
//program details...

 

Multi line comment

If you want to give, comment that space across more than one line then use multi line comment.

The multi line comment begins with /* and end with *\

Multiline comment is useful when the details about the code, the programmar, code update dates, etc needs to be given. Most commonly it is used in the beginning to provide the said details.

 

Example

This is how you can give multi line comments in C programming

/*
 Line 1
 Line 2
 Line 3
*\

As we got acquainted with the types of comment in C so its time to use them in real code.

Given below is an example that shows use of comments:

/*
Multi-line comment
Name:- Nikhil  Pandey
Date:- 28/06/2018
Example program
*/
#include<stdio.h>
#include<conio.h>
Void main()
{
	clrscr();
	// display details of programmer
	printf(“\n Name:- Nikhil Pandey”);
	printf(“\n DOB:-15/10/2000”);
	printf(“\n Course:- BCA”);
	printf(“\n Address:- vapi”);
getch();
}

OUTPUT:

Name:- Nikhil Pandey

DOB:- 15/10/2000

Course:-BCA

Address:- vapi

 

Significance of Comments

  • It helps write necessary details about the code like code purpose, author of code, updates, etc. 
  • Comment can be a useful debugging tool if used carefully and intelligently.
  • You can comment out the suspected portion of the code and check if your code runs fine.  

 



Please Share this page
Views : 103
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!