Question:medium

What is the purpose of the endl manipulator in C++?

Show Hint

If you only want to insert a newline and don't need to force a flush immediately (which can be more efficient in loops), you can simply insert the newline character:cout << Hello;`. Useendl` when you need to ensure the output is immediately visible.
Updated On: Jul 2, 2026
  • It only moves the cursor to the next line.
  • It only flushes the output buffer.
  • It moves the cursor to the next line and flushes the output buffer.
  • It inserts a tab space in the output.
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Remember why streams are buffered.
C++ output streams like cout do not usually write to the screen instantly, instead they collect characters in an internal buffer and send them out later purely for efficiency.
Step 2: Break endl into its two separate jobs.
First, endl inserts a newline character so that the next piece of output starts on a fresh line, and second, it explicitly forces, or flushes, whatever is currently sitting in the buffer to be written out immediately.
Step 3: Contrast it with a plain newline character.
If you only wanted the cursor to move down without paying the performance cost of flushing, you could use the escape character for newline instead, so the fact that endl also empties the buffer is exactly what makes it match the description of doing both jobs at once.
\[ \boxed{\text{It moves the cursor to the next line and flushes the output buffer.}} \]
Was this answer helpful?
0