Wednesday, October 21, 2009

C++ Comments : Types and Uses


C++ Comments : Types and Uses

Why to use commments ?

You write a program so that it performs the given set of instruction. When you increase the code by adding additional instruction to it, it may become confusing. You can use comments to simplify it by mentioning that how or what the given instruction does. If you give your code to any other programmer, it will be easier for him to understand your code if you use comments wisely. Also It will be helpful for you too. If you use comments you will have better idea about your program even if the program becomes large later on.

Types of comments

There are two types of comments used in C++.
(1) Single line comments :
Single line comments is accomplished by double-slash (//). Everthing that is followed by double-slash till the end of line is ignored by the compiler. It is reffered as C++-style comments as it is originally part of C++ programming.

(2) Multi-line comments :
Multi-line comments starts by using forward slash followed by asterisk (/*) and ends by using asterisk followed by forward slash (*/). Everthing between (/*) and (*/) are ignored by compiler whether it is one or more than one line. It is reffered as C-Style comment as it was introduced in C programming.

A C++ Program example that demonstrates the syntax and use of C++ Comments.


/*
Program : C++ Comments
Source code written by : Mohammed Homam
Last modified date : 8:09 PM 10/21/2009
*/

#include <iostream>

int main ()
{

    using std::cout;
    using std::endl;

    cout << "C++ Programming" << std::endl;    // It will display
                                                                         // C++ Programming
    return 0;
}

Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.
Want to learn more? View List Of All Chapters

20 comments:

  1. thanks a lot.. everything here is brief and complete.

    ReplyDelete
  2. please help me....to write this program

    Write a C++ program that performs various calculations for a rectangle shape. Your program should provide the functions that calculate the perimeter and the area of the rectangle. Include a boolean function isSquare which determines whether the rectangle is a square. Ask the user to enter the width and height of the rectangle. Display the results.

    ReplyDelete
  3. please show a program of calculator (+,-,*,/)usin if else

    ReplyDelete
  4. Get Your NADRA Birth Certificate, Police Certificate, Marriage Certificate And WES Attestation From Karachi, Lahore, Islamabad, or Anywhere in Pakistan at MamooInPakistan.com https://www.mamooinpakistan.com/

    ReplyDelete
  5. https://begincpp.blogspot.com/2009/10/c-comments-types-and-uses-why-to-use.html?showComment=1486463382170#c6644781284607144279

    ReplyDelete
  6. What we need to do to avoid this kind of irreversible how to access iphone with broken screen damage? Data recovery is not possible after its infection because the private key is stored on hacker servers.

    ReplyDelete
  7. Best wishes of this programming site.It is the very difficult work manage that its programmer site.I hope that my best programmer site 2018 of public user that like its.

    ReplyDelete
  8. Your way to enlighten everything on this blog is actually pleasant, everyone manage to efficiently be familiar with it, Thanks a great deal.
    c++ programming tutorial

    ReplyDelete
  9. Your blogs are easily accessible and quite enlightening so keep doing the amazing work guys.
    c++ programming tutorial

    ReplyDelete
  10. I found useful article in your blog. thank you
    visit
    web programming tutorial
    welookups.com

    ReplyDelete
  11. I imagine this post. I think this site is very strong! Continue ...

    Click Here : Crawler dozers for sale Cat D5KXL KWW00358

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Is this a valid comment; // this is an /* invalid */ comment

    ReplyDelete
  14. You won't believe me, but I was planning to write a blog very similar to the one you have posted here. Great work!

    Java Training In Chennai

    AWS Training In Chennai


    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Nice knowledge gaining article. This post is really the best on this valuable topic.
    代做java

    ReplyDelete
  17. Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon!
    cs作业 代写

    ReplyDelete