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