How to use comments in C
Hello Everyone, Welcome back to Think & Free. Here is another episode of Express Learning Programming with the C Programming Language Programming Series. If you have already read our latest article, I think you now know the basic idea and programming structure of a C program. So here today I’m going to show you another basic but useful programming concept, which is comments. So let’s begin with today’s lesson about how to use comments in the C programming language.
Before getting into the article, let’s first see what those comments are and why we need comments in programming.
What is Comments?
Comments are another crucial part of programming. It’s one of the most basic but most used concepts In every programming language, why are comments used? Let’s see what the purpose of using comments is.
In programming, sometimes we work with heavy projects with a huge number of code lines, so when we take a look at the code after a few days, sometimes we cannot be able to identify or realize the logic. Here are the comment’s needs: We are using comments to take notes about code lines. It helps make the program easier for developers. Another thing is that sometimes comments are used to temporarily deactivate some code lines. This might help identify some bugs in your code.
What does the compiler do for comments?
In every programming language, comments will be ignored when execution happens. So when it comes to the compiled programming languages, the same thing happens, and the compiler will ignore comments during the compilation process. That means the compiler didn’t include comments for compiled files. As I noticed before, comments only allow the developer to see, create, and edit, and they don’t affect the execution process, which means comments are completely ignored. Let’s see how we can use it.
Comments in C
Comments and their syntax will differ from language to language. Basically, in the C programming language, we can see two types of comments. Let’s look at what they are.
- Multi-line or Block Comments
- Single-line Comments
These are the two types of comments we can use in the GNU C programming language. The multi-line comments will allow you to create a block of comments or something like a paragraph or something like that. All these comments can be used anywhere in your program; comments are not location-specific.
C Multi-line Comment
This type of comment will allow you to set multi-line comments in C, it’s like you can use some comments like paragraphs. Let’s see how to use this type of comment in C.
Multi-line comments will start with /*
and end with “*/
“, and every piece of content in these “/* */
” blocks will ignore the compiler in the compilation process. It only allowed the developer to take note of codes.
C Single-line Comment
Here is another type of comment syntax we can use in the C programming language. Let’s see how to use it. If in any line we can start this type of comment using “//
“.
Here is the example code below:
/* C comments Example by Think & Free This is a Multi line comment in C Here is the third line. */ #includeint main() { // Print 'Hello, World' String on Console window printf("Hello, World\n"); return 0; }
Look at the code, now you can compile and run this code and see the result (If you don’t have an idea of how to compile and run C code). (Check out our previous lesson.). It will only provide output for “printf(“Hello, World\n”);”. I think that’s enough to, Get some idea about “Comments” in C. See you back soon with another episode of this Express Learning Programming Win GNU GCC Programming Language. “Practice is the only way to learning.