0
What are comments, and what are there purpose also can u use endl and \n both in one
2 Réponses
+ 6
"endl" is a stream manipulator and it sends a newline character '\n' and flushes the output buffer, while \n is simply \n.
+ 4
Suppose you are writing a code for someone else.
and the code is pretty much lengthy and complex.
Now tell me how can you assure that other person will understand your code efficiently and quicker...
here comes the role of comments
so that your code would be readable with ease.
and-
if in case you are working on a project software, which may be... take a month to complete.
so without comments you will find even yourself in confusion whenever you would look back into your weeks back code sample.
COMMENTS ARE USEFUL TO ENHANCE THE READABILITY OF A CODE.
You can use \n in strings like
cout<<"hello\nworld\n";
but endl need to be use outside like.
cout<<"hello"<<endl<<"world"<<endl;
and also you may write like.
cout<<"hello\nworld"<<endl;
Output would be same in all 3.