What are coroutines in C++20, and how do they differ from standard functions in terms of stack management?

Last updated 21 June 2026

  • A coroutine is a function that can suspend and later resume with its local state preserved. Any function using co_await, co_yield, or co_return is a coroutine.

  • C++20 coroutines are stackless: locals and the resume point live in a heap-allocated coroutine frame, not on the call stack. A normal function's frame is popped on return, but this frame persists until resumed or destroyed.

  • The language supplies only the machinery. A return type with a promise_type (or a library type like std::generator) defines suspension behavior, which suits generators and async I/O.

  • https://dev.to/leapcell/concurrency-in-go-vs-rustc-goroutines-vs-coroutines-27f5
  • https://dev.to/aregtech/c20-coroutines-vs-event-driven-frameworks-two-approaches-to-async-programming-58ej
All C++ interview questions