Microcontroller Embedded C Programming Lecture 21| Commenting in ‘C’

  • Post author:
  • Post category:Blog

 

Comments in ‘C’

 

 

 

Comments in C

  • Comments are used to provide the description or documentation about the code you have written.
  • Through commenting you can mention important note, briefly explain behavior of the code, and other useful details.
  • Comments help the developer understand the logic/algorithm of the code if he/she revisits the code after a long time.
  • You can mention the comments anywhere you want in the program, and the compiler will ignore your comments. 
  • Comments do not affect programs or they do not consume any program memory space. They are not part of the final executable generated. It is there just for the documentation purpose.

 

 

Types of Comments in C: 

There are two types of comments:

  1. Single line Comments

Single line comments can be provided by using //…………… 

It uses two forward slashes.

 

  1. Multi-line Comments

Multi-line comments can be provided by using /*………………*/

In multi-line commenting, you have to write a comment between a combination of a forward slash(/) and asterisk(*). 

 

 

Example:

This is an example of Multi-line commenting.

Comments in C
Figure 1. Example of Multi-line comments

 

Here, the comment should start from a forward slash(/) followed by an asterisk(*). And after that, whatever the comment you want to write, you can write it here. So, multiple lines of comments are involved, and then you end the commenting by using an asterisk(*) followed by the forward slash(/). That’s what we call multi-line commenting.

 

Comments in C
Figure 2. Example of Single line Comments

 

The first comment should begin with two forward slashes(//) in the single line commenting.

 

The example of single-line and multi-line commenting are shown in Figure 3.

Figure 3. To write a Comments on the program
Figure 3. To write a Comments on the program

 

In program, to start multiple line commenting, you can begin with a forward slash followed by an asterisk(/*), and after that, you can write whatever you want; I write ‘this is my first program’. After that, you end the commenting by using an asterisk followed by the forward slash(*/).

Here, if you want to add one more line, you can give enter and add one more comment. So, ‘this is comment line 1’, and after that, you can add one more line, ‘this is comment line 2’, like that. So, you can see that all the lines are in between these markers(/*…..*/). So, this is what we call multi-line commenting.

You have to use double forward slashes(//) for a single-line comment for each line.

In the following article, let’s explore ‘C’ data types and variables. 

 

Get the Full Course on Microcontroller Embedded C Programming Here.

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply