Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

In C++ I/O streams, output is often buffered. This means that when you usecout`, the data might be stored in a temporary memory area (a buffer) instead of being written immediately to the output device. This is done for efficiency.
Theendl` manipulator performs two distinct actions:
1. Inserts a newline character: It writes a newline character (``) to the output stream, which causes the cursor to move to the beginning of the next line on the console. 2. Flushes the output buffer: It forces any data currently held in the output buffer to be written to the final destination (e.g., the screen) immediately.
Therefore,endl` both moves the cursor to the next line and flushes the buffer.
Was this answer helpful?
0
0