Name

void keyword — Absence of type or function arguments

Synopsis

               simple-type-specifier := void

The void keyword can be used as a type specifier to indicate the absence of a type or as a function’s parameter list to indicate that the function takes no parameters.

When used as a type specifier, it is most often used as a function return type to indicate that the function does not return a value. It is also used as a generic pointer (e.g., void*), although this usage is needed less often in C++ than in C.

C++ does not require that void be used to indicate that there are no function parameters, but it is often used in this way for compatibility with C.

Example

void func(void)
{
  std::cout << "hello, world\n";
}

See Also

declaration, type, Chapter 2, Chapter 5

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.