What are comments in c++??
Comments are generally those line which will not compile and use for remember the aim/purpose of code.
Why to write comments??
Comments written in any programming language is very essential . Comments are the description that let us know what is going on in a particular code of segment.
A good programmer or you can say a professional programmer language always contains comments . If a programmer is not writing a comment then other person viewing it may get confuse or may not understand what is happening in that block of code . Now most of you would be thinking why to explain your codes to others …??? Well , you see if you coding something for your own purpose then its upto you whether to write comments or not , but its better if you write because if you forget what codding you did it will help you to remember that n will save time . If you are coding for someone else like programmers generally do in offices then its necessary to write comments otherwise how would other person checking your code or referring your code will get to know what you did ..
There are two types of comments :
- single lined
- multi-lined
For single – lined SYNTAX
“//”
For multi- lined SYNTAX
“/* hsgjcfhfdkjs
dbscjnmd,bsvkj
ncbds,fv
*/”
Now when you use them remember don’t put these” ” , i have used them for highlighting the main syntax …
Lets try it in code:
#include<iostream> /*visual studio and gcc compiler use iostream while turbo c use iostream.h as input output header file */
using namespace std; //It is use for std I/O ex- Cout
//if skip above line ,we must use std::cout<<“buffercode”;
int main( ) //it is the main function of the programme
{ //braces start
cout<<“hello buffercode” ; // it prints hello buffercode
/* semicolons are must to tell
———-the compiler where line ends—- */
return 0; // programme must return a integer value
} //end of function
Output:
hello buffercode