Make your own free website on

C++ Intro (Part 2) by Amin Patel

Before you learn something. Start with a prayer to God, that you “Succeed in learning C++”.

Almost every time the teacher gives lesson in school, we might copy everything from the board or make notes over what is taught. There is a similar thing we call in c++, ‘Comments’. Comments can be used for different purposes.

·   The most obvious one, to recall the purpose of the code (Say you are referring to it after 6 months, makes less sense then. If you don’t include a comment.)

·   Helps your computer teacher know what you have actually written. Just kidding.

·   Now this one is an unobvious reason. Sometimes after compiling you might want to remove some line just to see how your program works then, without deleting the actual code.

·   The final one, just a good programming style to express your thoughts.

Comments can be written anywhere in the program (Good Feature). They don’t effect your code, unless you comment out something by mistake. 

There are two types of comments:

  1. C Style: 

/* You can write anything that makes sense here */

After the introduction of c++ it just become a norm for programmers to ‘Comment out’, huge parts of their code using this style. The initial part (/*) and the final part(*/) can be on separate lines.


  1. #include <iostream.h>
  2.  int main()
  3. {/*
  4. cout<< “ This whole line gets, commented out!”;*/
  5. }


<Warning: The numbered indentation is not to be included with the code while typing. It is only for your convenience>  

  1. C++ Style

// After the 2 slashes, you can type anything that makes sense.

This comment style is used more often these days but please note that if your comment sentence goes over many lines, please use // on each line at the beginning.


  1. #include <iostream.h>
  2.  int main()
  3. {
  4. cout<< “How are you I am fine”;
  5. // Line 4 will print “How are you I am fine, to the screen.
  6. // Notice that I placed the 2 slashes on this line too.
  7. }

Add your tutorials to this site Mail Me



GauravCreations's Store / Home / Register / Awards / Opinions / Downloads / Query

Linux Hosting India | Linux Forum

Copyright © 2001-04 [Gaurav Creations]. All rights reserved