Use of endl in C++

As told, endl; is used to tell that our c++ statement is ended. I wanted to ask that what if we don’t use endl; , do it have any effect irrespective of that it gives next output in a new line?
is it alright to finish any c++ statement with a semicolon without using endl;?

for example:- cout<<“Hello world”;

yeah , you can use cout << “Hello world”; without an endl;
endl just makes sure that the next thing to be typed is typed from a new line, which looks neater.

hey @himanshigupta579 cout<<endl has to be used when you want to print something in a new line, and this new line is taken in reference to what you have already printed.
For eg:- cout<<“Hello”;cout<<“World”; gives the output as
HelloWorld
where as cout<<“Hello”<<endl;cout<<“World”; gives the output as
Hello
World
So using endl depends on what you really want to output.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Thank u for clearing my doubt.

1 Like