What are Coroutines in C++20, and what are their primary use cases?

Last updated 21 June 2026

  • Coroutines are functions that can suspend and resume, preserving local state (usually in a heap frame). Any function using co_await, co_yield, or co_return is one.

  • Main uses: async I/O written sequentially with co_await, lazy generators via co_yield, and callback-free state machines.

  • C++20 provides only the language machinery, so you need a library or custom promise types (std::generator arrives in C++23).

  • https://www.geeksforgeeks.org/interview-prep/advanced-topics-design-patterns-interview-questions-c-programming/
  • https://www.geeksforgeeks.org/cpp/cpp-23-standard/
  • https://www.geeksforgeeks.org/cpp/cpp14-vs-cpp17-vs-cpp20/
  • https://www.simplifycpp.org/?id=a0198
All C++ interview questions