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.