Although they both seem to do the same thing, there is a subtle difference between them.
cout << endl : Inserts a new line and flushes the stream cout << " " : Only inserts a new line.
cout << endl;
can be said equivalent to
cout << ‘ ’ << flush;
So cout << “ ” seems performance wise better than cout << endl; unless flushing of stream is required.
Some other differences between endl and are:
- endl is manipulator while is character.
- endl doesn’t occupy any memory whereas is character so It occupy 1 byte memory.
- We cannot write endl in between double quotation while we can write
in between double quotation like
cout<<" "; it is right but cout<<"endl"; is is wrong.
- We can use also in C++ but we can't use endl in C language.