{"id":2138,"date":"2024-05-10T07:12:12","date_gmt":"2024-05-10T07:12:12","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=2138"},"modified":"2024-05-10T07:12:12","modified_gmt":"2024-05-10T07:12:12","slug":"c-comments","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/c-comments\/","title":{"rendered":"C Comments"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#c-comments\">C Comments<\/a><\/li><li ><a href=\"#when-and-why-to-use-comments-in-c-programming\">When and Why to use Comments in C programming?<\/a><\/li><li ><a href=\"#types-of-comments-in-c\">Types of comments in C<\/a><\/li><li ><a href=\"#1-single-line-comment-in-c\">1. Single-line Comment in C<\/a><ul><li ><a href=\"#example-1-c-program-to-illustrate-single-line-comment\">Example 1: C Program to illustrate single-line comment<\/a><\/li><\/ul><\/li><li ><a href=\"#2-multi-line-comment-in-c\">2. Multi-line Comment in C<\/a><ul><li ><a href=\"#example-2-c-program-to-illustrate-the-multi-line-comment\">Example 2: \u00a0C Program to illustrate the multi-line comment<\/a><\/li><\/ul><\/li><li ><a href=\"#faq-c-comments\">FAQ- C Comments <\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c-comments\">C Comments<\/h2>\n\n\n\n<p>In C, comments are notes in the code that humans can read. They don&#8217;t affect how the program runs, but they make the code easier to understand. It&#8217;s a good practice to use comments to explain your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"when-and-why-to-use-comments-in-c-programming\">When and Why to use Comments in C programming?<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Improving  Readability<\/strong>: Without comments, large and complex code can be confusing and challenging to understand. Comments provide essential details and context, making it easier for anyone reading the code to follow along.<\/li>\n\n\n\n<li><strong>Descriptive Documentation<\/strong>: Comments serve as a form of documentation, explaining the purpose of functions, algorithms, and code segments. This documentation helps programmers and maintainers understand how the code works.<\/li>\n\n\n\n<li><strong>Algorithm Explanations<\/strong>: Comments can be used to describe algorithms, making the code&#8217;s logic and methodology clear. This is particularly useful for complex or non-intuitive algorithms.<\/li>\n\n\n\n<li><strong>Code Control<\/strong>: Comments can also be used strategically to comment out (prevent execution) of certain code sections during debugging or testing without actually removing the code.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-comments-in-c\">Types of comments in C<\/h2>\n\n\n\n<p>In C there are two types of comments in C language:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Single-line comment<\/strong><\/li>\n\n\n\n<li><strong>Multi-line comment<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-single-line-comment-in-c\">1. Single-line Comment in C<\/h2>\n\n\n\n<p>In the C programming language, a single-line comment is denoted by two forward slashes (<code>\/\/<\/code>). When you include <code>\/\/<\/code> in your code, everything from that point until the end of the line is treated as a comment by the compiler and is not executed as code. This allows you to add explanatory notes or comments to your code without affecting the program&#8217;s functionality.<\/p>\n\n\n\n<p>Syntax of Single -line Comment<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ This is a single line comment\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-1-c-program-to-illustrate-single-line-comment\">Example 1: C Program to illustrate single-line comment<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to illustrate\n\/\/ use of single-line comment\n#include &lt;stdio.h&gt;\n \nint main(void)\n{\n    \/\/ This is a single-line comment\n    printf(\"Welcome to Skill vertex\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to Skill vertex<\/code><\/pre>\n\n\n\n<p><strong>Comment at End of Code Line<\/strong><\/p>\n\n\n\n<p>We can also make  a comment that shows at the end line of code using a single-line comment. But , it\u2019s most preferable in  putting the comment before the line of code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ C program to demonstrate commenting after line of code\n#include &lt;stdio.h&gt;\n \nint main() {\n    \/\/ single line comment here\n   \n      printf(\"Welcome to Skill vertex\"); \/\/ comment here\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to Skill vertex<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-multi-line-comment-in-c\">2. Multi-line Comment in C<\/h2>\n\n\n\n<p>In C, multi-line comments are enclosed between <code>\/*<\/code> and <code>*\/<\/code>, and anything between these delimiters is treated as a comment and ignored by the compiler. This allows you to add comments that span multiple lines in your code, making it easier to provide detailed explanations or temporarily exclude blocks of code from execution.<\/p>\n\n\n\n<p>Syntax of a multi-line comment in C:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*Comment starts\n    continues\n    continues\n    .\n    .\n    .\nComment ends*\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-2-c-program-to-illustrate-the-multi-line-comment\">Example 2: &nbsp;C Program to illustrate the multi-line comment<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* C program to illustrate\nuse of\nmulti-line comment *\/\n#include &lt;stdio.h&gt;\nint main(void)\n{\n    \/*\n    This is a\n    multi-line comment\n    *\/\n   \n      \/*\n    This comment contains some code which\n    will not be executed.\n    printf(\"Code enclosed in Comment\");\n    *\/\n    printf(\"Welcome to Skill Vertex\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to Skill Vertex<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-c-comments\">FAQ- C Comments <\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1695726545858\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1.What are types of comments?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. There are basically  two types of comments <br \/>Line comment<br \/>Block comment<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1695726552188\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2.What are the 3 types of comment?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. <strong>Single-line comments.<\/strong>\u00a0<strong>Multi-line comments.<\/strong>\u00a0<strong>Documentation comments<\/strong><\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1695726558643\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is comment method?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. A method comment, often referred to as a function or method documentation comment, is a detailed comment placed at the beginning of a function or method in the source code. Its purpose is to provide a clear and comprehensive description of the method&#8217;s functionality, its parameters (including their types), return type, and possibly other important information<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>C Comments In C, comments are notes in the code that humans can read. They don&#8217;t affect how the program runs, but they make the code easier to understand. It&#8217;s a good practice to use comments to explain your code. When and Why to use Comments in C programming? Types of comments in C In &#8230; <a title=\"C Comments\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/c-comments\/\" aria-label=\"More on C Comments\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":5318,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[377],"class_list":["post-2138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-c-comments","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=2138"}],"version-history":[{"count":14,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2138\/revisions"}],"predecessor-version":[{"id":10630,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/2138\/revisions\/10630"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/5318"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=2138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=2138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=2138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}