Comments in C // Programming Language | How to

Comment is very important in coding. Assume you have a very big team with a lot of loaded code in the application. There will be many functions and logic, which after a year or month will be not remembered by humans. So to know what every function or any stuff importance its required to add a comment above it. This tutorial we will learn how to do “Comments in c //” and type with examples.

How to Comments in C Programming Language

Types of comments in c

There are 2 types of comments in c language.

  • Single line Comments
  • Multiline Comments

This tutorial you will learn both type comment with tips and some interview questions.

 

Syntax

Simple syntax for comments.

or multiline

or

 

Single line Comments Example 

Here is an example of comments in c where the First 2 statement in the code is a comment. Here simple Hello world example in C with single line comment.

 

Multiline Comments Example 

Comment can be split into multiple lines in C. Which we called multiline comments.

 

Important Tips & Points

Here are some useful Tips and point on when doing comments in c code.

  • A comment is not necessary but a good practice to show the use of statements in the program.
  • You can write a comment in code as many you want.
  • No need to write so many comments, it suggested being specific and limited.
  • Can write any place in the program.
  • A normal language rules not applied in a comment like small, uppercase etc.

 

Question: What are the Advantages of using comments in programming?

Answer: A Advantage of comments in c programming is when a team building a very big application that time a well-commented code is easy to understand to other team members. And also for you when you are going for some changes in code.

Sometimes you don’t need only for describing code. It can use a show author name and date of created at stating in code, same as above example.

 

Question: Where I can write a comment in C program?

Answer: You can write a comment at any place in the program, for an example before the statement or after the statement or within the statements. See the below example.

This tutorial is for the beginner. Do comment if you have any doubt or questions.

 

Note: This example (Project) is developed in Dev-C++ and Version 5.11

Download link for IDE – Dev-C++


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.