Header Ads

ad728
  • Breaking News

    Comments in C language

    C - Comments what is the use of comments and how to write comments in c language.
    In C-language we have two type of Comments one is Single line comments and second one is Multi Line comment.

    Single Line Comment


    Comments are non-executable code used to provide documentation to programmer. Single line comment out just single line in the code. It is used to provide One Liner Description of line.

    Important Points


    1. Sinle line comment placed in Any where
    2. Single line comment start with "//"
    3. Any symbols writeen afer"//" ignored by compiler
    4. Comment can not hide statements written before "//" and on the successive new line

    Example


    #include < stdio.h >
    void main()
     {
    printf("Hello"); //Single line comment
    printf("Bye");
    }

    Explanation


    • In the above code we have included single line comment.Single line comment can be used in any where in the program
    • Single line comment ignores the complete line form the position where it has been written. There for single line comment usually after ending of statement.

    Multi Line Comment


    1. Multi line comment placed any where in program.
    2. Multi line comment start with /*.
    3. Multi line comment ends with */.
    4. Any symbols written between '/* and */' are ignored by compiler.
    5. It can split over mulitple lines.

    Example


    #include < stdio.h >
    void main()
     {
    printf("Hello"); /* Multi line comment */
    printf("Bye");
    }

    Rules of Writing Comments in C


    1. Program contain any number of comments at any place.
    2. Nested comments are not allowed. i.e Comment with in comment.
    3. Comments an be split over more than one line.
    4. Single comments starts with '//'.

    Difference between Single line and multi line Comments


    Single line CommentMulti line comment
    Single line comment start with '//'.Multi line comment start with */ and ends with */
    statements after the symbol // upto the end of line ignored.All words and statements writing between /* and */ are ignored.
    Comments ends whenever ENTER is pressed New line Starts.Comments ends when */ occurs.
    eg. // Single line commenteg./* Multi line comment*/

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728