TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    C Tutorials

    C Comments

    Overview

    In this tutorial, we will learn about C Comments. It is a good programming practice to add comments to the code so that others can understand the code and logic.

    The C compiler ignores the comments in the code when it translates the C program into executable machine code.

    C Comments

    C language uses three types of comments. They are as follows:

    • Line comment( // )
    • Block comment( /* ….  */ )
    • Document Comment ( /**  … */ )

    Line comment

    The line comment is also known as a single-line comment. The single-line comment uses two slashes to identify it as a line comment. The end of the line automatically ends the line comment.

    The programmer usually uses single-line comments to write short descriptive text in the program code.

    Single line comment example:

    Single Line C Comments

    Block comment

    The block comment is also known as a multi-line comment.  The multi-line comment uses opening and closing comment tokens. A token is a combination of one or more symbols with a special meaning understood by the C compiler.

    The multi-line comment starts with a /* and ends with a */ token. The compiler ignores all the comment text between the /* and */ comment symbols.

    A block comment can span several lines. The programmer usually uses multi-line comments when the comment text contains several lines.

    Multi-line comment example:

    Multi-line C Comment

     

    Document Comment

    This comment is mostly used at the top of the C program. The document comment is used to add program attributes, program documentation, license information, etc.

    The document comment starts with a /* * and ends with a */ token. The compiler ignores all the comment text between the /**  and */ comment symbols.

    Document comment example:

    Document C Comments Program

    Notice that the IDE highlights the comment text with a different color.

    C Program

    Sample C demo program with the comments.

    /**
    **********************************
    * Program Description:
    * C Comments Demo
    * Filename : commentsDemo.c
    * Author : TestingDocs
    * Date : 07/08/2017
    * C Tutorials - www.TestingDocs.com
    *************************************
    */
    #include<stdio.h>
    int main()
    {
     /* C Variable Declaration
     Initialization Demo Program
     C Tutorials - www.TestingDocs.com
     */
     int number = 20; // declare number
     double interestRate = 0.15;// declare interest rate
    
    
     printf("Number = %s \n",number); // print number
     printf("Interest Rate = %lf \n",interestRate);
    
     return 0;
    } // end main

    That’s it.

    —

    C Tutorials

    C Tutorials on this website can be found at:

    https://www.testingdocs.com/c-language-tutorial/

    Related Posts

    C Language Characteristics

    C Tutorials /

    C Language Characteristics

    C Source Code .c File

    C Tutorials /

    C Program Files & Formats

    GNU Compiler Collection GCC

    C Tutorials /

    C Compilers

    C Pointers

    C Tutorials /

    C Pointers

    C Tutorials /

    C Two-Dimensional Arrays

    ‹ Compile and Execute C Program› C if Statement

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com