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


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

  2. please help 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.

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

  4. Get Your NADRA Birth Certificate, Police Certificate, Marriage Certificate And WES Attestation From Karachi, Lahore, Islamabad, or Anywhere in Pakistan at


  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.

  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.

  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

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

  10. I found useful article in your blog. thank you
    web programming tutorial

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

    Click Here : Crawler dozers for sale Cat D5KXL KWW00358

  12. This comment has been removed by the author.

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

  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

  15. This comment has been removed by the author.