What are comment lines in c programming?
Comment lines in c programming provides piece of information about some statements of code.
Usually they are the descriptions or explanation for a specific piece of code.
Comments are not executables, they are ignored by compiler.
Comments can be used anywhere in program.
It is optional to use comment lines but it is a good practice to use it.
In c programming language there are two types of comments. They are
- Single line comment
- Multiline comment
Single line comments
Single line comments starts with double slashes //
.
Syntax
// Comment line
Example
#include<stdio.h>
int main()
{
int var1; // This is integer variable declaration
printf("\n\n\tThis is a program to demonstrate single line comments in c programming\n\n");
return 0;
}
In the above program, we have commented that var1 is an integer variable. By doing this programmer can understand the usage of that line.
This is a program to demonstrate single line comments in c programming
Try it yourself.
Multiline comments
Multiline comments are placed between /*…….*/. It is used to make many lines of comments.
Syntax
/*
multi line comments
*/
Example
#include<stdio.h>
int main()
{
int var1=10;
printf("This is integer variable %d \n",var1);
/*
This is
simply a line
to print
on console */
return 0;
}
When one has to comment in multiple lines then this multiline comments are helpful.
This is a program to demonstrate multiline comment This is integer variable 10
Try it yourself.
People also ask for
What are comments in c?
Comments gives piece of information about some statements of code. They are written in English language and are part of program.
How many types of comments are there in c?
There are two types of comments in c. They are 1.Single line comment 2. Multiline comment.
Are comments in code necessary?
No comments are not mandatory. But writing comment line for programs increases the readability, understandability.
Why you should comment your code?
Comment lines desribe the program. If a program contains good comment lines then it can be used to refactor, maintain the code.
Why do you need comments?
Comments are needed to understand, refactor, maintain the program.
People also read
- C program Structure
- Structures in c
- Arrays in c
- string in c
- printf in c
- Comments in c programming
- scanf in c