What are comments i…
 
Notifications
Clear all

What are comments in programming? Why are they used?

2 Posts
3 Users
3 Likes
480 Views
0
Topic starter

Define comments and their uses.

2 Answers
2

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.

1

A comment is used to make small notes during the course of programming. It makes the programmer’s work much easier. There are times when programmers have to write long codes, and after a few days when they try to remember what they did in that given code, they may start having a difficult time in recalling whatever they wrote in that code. Therefore, comments are written to avoid having to understand code over and over again and they can just understand what their code is doing just by looking up at the comments. The comments are not included in the flow of the program.

For example:

In python,

# This code is for printing "hello world", 10 times
for i in range(10):
    print("Hello World");

Here, the content after the # (hash) is used to denote a comment in python, and to describe the code given below is for printing “hello world” ten times.

Share: