C++20 sections · 1024 units
Open in Course

Void Functions

Functions that just do work

Not every function gives back a value. Some just do work like printing output. These use void as return type. void means "returns nothing." You call it for the side effect. Example: void greet() { cout << "Hello!\n"; }.

Call with greet(); and it runs, but there's no value to store. Trying int x = greet(); causes a compiler error. Use void when the job is to change state or produce output, not calculate.

Printing, logging, updating counters are all void territory.