TEA BREAK WITH C++: Line Comments

NOTE: You may download codes and extra source material for this book from https://bookofengineering.com/easyseries/

The “//” sign means you are adding a comment. This is called line comment. The things you write after these “//” will not be taken as a command (means these things will not be compiled). It is always a good approach to write down the properties of the code at the beginning like author, for which aim this code is written etc. 

You can also line comment after a code; 

  1.  //my first c++ program
  2. #include <iostream>
  3. using namespace std; 
  4. int main(){
  5. cout<<“hello world!”; // this is my first print on screen
  6. return 0;
  7. system(“pause”);
  8. }

Here on the line #5 you see that “//” is used after a command. So, we can also explain what some part of the code means and we will use these as much as possible so that the other programmers that try to modify the code we wrote will be easily getting the idea. There is always a saying between the programmers like “it is easy to code from scratch compared to modify a code written by someone else”. And that is pretty true especially if the programmer is untidy. 

NOTE: You may buy this course in paperbook book format from https://www.amazon.com/dp/B0892HQTGS

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.