void

suggest change

An incomplete type; it is not possible for an object to have type void, nor are there arrays of void or references to void. It is used as the return type of functions that do not return anything.

Moreover, a function may redundantly be declared with a single parameter of type void; this is equivalent to declaring a function with no parameters (e.g. int main() and int main(void) declare the same function). This syntax is allowed for compatibility with C (where function declarations have a different meaning than in C++).

The type void* (“pointer to void”) has the property that any object pointer can be converted to it and back and result in the same pointer. This feature makes the type void* suitable for certain kinds of (type-unsafe) type-erasing interfaces, for example for generic contexts in C-style APIs (e.g. qsort, pthread_create).

Any expression may be converted to an expression of type void; this is called a discarded-value expression:

static_cast<void>(std::printf("Hello, %s!\n", name));  // discard return value

This may be useful to signal explicitly that the value of an expression is not of interest and that the expression is to be evaluated for its side effects only.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


keywords:
* class
* float
* bool
* void
* char
* short
* long
* double
* int
* enum
* if
* do
* else
* true
* false
* const
* for
* goto
* struct
* case
* catch
* return
* signed
* static
* this
* switch
* throw
* try
* break
* union
* asm
* sizeof

Table Of Contents
8 Arrays
11 Loops
14 keywords
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype