What is endl in C++?

In C++, endl is a manipulator used with output streams like std::cout to insert a newline character (\n) and flush the output buffer. It ensures that the output is immediately written to the console or file, which is particularly useful when dealing with buffered output.

Example of endl Usage:

#include <iostream> using namespace std; int main() { cout << "Hello" << endl; // Outputs "Hello" followed by a newline cout << "World" << endl; // Outputs "World" followed by a newline return 0; }

Key Points:

  • Newline: endl inserts a newline character (\n), moving the cursor to the next line.
  • Buffer Flush: It also flushes the output buffer, meaning the content is immediately sent to the console or file. This is important in situations where you want to ensure that the output is not delayed, like when debugging.

endl vs \n:

  • endl: Inserts a newline and flushes the buffer.
  • \n: Only inserts a newline without flushing the buffer, making it more efficient for performance in scenarios where frequent flushing is not necessary.

In most cases, if you do not need to flush the buffer, using \n is preferred for performance reasons.

Sources:

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
How to implement a tree data-structure in Java?
Where is Netflix's headquarters?
What is a mock schedule?
What is the minimum age for Microsoft?
What counts as IT skills?
What is a CV in tech?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.8
(1,192 learners)
Discounted price for Your Region

$123

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.