ArticleslgStudy

science

Void type

Void type is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Void type rather than just read about it. In short: The void type, in several programming languages, more so curly bracket programming languages derived from C and ALGOL 68, is the return type of a function that returns normally, but provides no result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their input parameters.

Key takeaways

  • Void type belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Void type to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Void type from memory before moving on to harder problems.

Reference excerpt

The void type, in several programming languages, more so curly bracket programming languages derived from C and ALGOL 68, is the return type of a function that returns normally, but provides no result value to its caller. Usually such functions are called for their side effects, such as performing some task or writing to their input parameters. The use of the void data type in such context is comparable to procedures in Pascal and syntactic constructs which define subroutines in Visual Basic. It is also similar to the unit type used in functional programming languages and type theory. See Unit type#In programming languages for a comparison. C and C++ also support the void pointer (or pointer to void type), denoted void*, but this is an unrelated notion. Variables of this type are pointers to data of an unspecified type, so in this context (but not the others) void* acts roughly like a universal or any type; it does not literally "point" to a void in memory. A program can convert a pointer to any type of data (except a function pointer) to a pointer to void and back to the original type without losing information, which makes these pointers useful for polymorphic functions. The C language standard does not guarantee that the different pointer types have the same size or alignment.

In C and C++ A function with void result type ends either by reaching the end of the function or by executing a return statement with no returned value. The void type may also replace the argument list of a function prototype to indicate that the function takes no arguments. Note that in all of these situations, void is not a type qualifier on any value. Despite the name, this is semantically similar to an implicit unit type, not a zero or bottom type (which is sometimes confusingly called the "void type"). Unlike a real unit type which is a singleton, the void type lacks a way to represent its value and the language does not provide any way to declare an object or represent a value with type void. In other C-derived languages, such as Java and C#, void exists similarly with the same use. While Java does not have explicit pointers, C# has void* inside of unsafe blocks. In the earliest versions of C, functions with no specific result defaulted to a return type of int and functions with no arguments simply had empty argument lists. Pointers to untyped data were declared as integers or pointers to char. Some early C compilers had the feature, now seen as an annoyance, of generating a warning on any function call that did not use the function's returned value. Old code sometimes casts such function calls to void to suppress this warning. By the time Bjarne Stroustrup began his work on C++ in 1979–1980, void and void* were part of the C language dialect supported by AT&T-derived compilers. The explicit use of void vs. giving no arguments in a function prototype had different semantics in C and C++, as detailed in this table:

The C syntax to declare a (non-variadic) function with an as-yet-unspecified number of parameters, e.g. void f() above, was deprecated in C99. In C23 (and C++), a function prototype with empty parentheses declares a function with zero parameters. In C and C++, one can write a "void cast" to explicitly indicate to discard a value.

In Haskell

In contrast to C++, in the functional programming language Haskell, the void type denotes the empty type, which has no inhabitants. A function into the void type does not return results, and a side-effectful program with type signature IO Void does not terminate, or crashes. In particular, there are no total functions into the void type. In functional programming, the unit type would replace the use of the void type in C. This type has a unique result which provides no new information.

In Rust In Rust's foreign function interface, there exists a std::ffi::c_void type equivalent to C/C++ void. There is no native void in Rust, as it uses the unit type ().

See also Null pointer

References

Worked examples

Example 1 — a first encounter with Void type

Start with the simplest possible case. Write down what Void type claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Void type before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Void type ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Void type

In research
Void type appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Void type in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Void type is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data types, Type theory, Unknown content, so understanding it makes those chapters shorter.
In everyday life
Look for Void type outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Void type” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Void type in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Void type means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Void type out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Void type in simple terms?

The void type, in several programming languages, more so curly bracket programming languages derived from C and ALGOL 68, is the return type of a function that returns normally, but provides no result value to its caller. Usually such functions are called for their side effects, such as performing…

Why does Void type matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Void type?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Void type.

Tags

  • Data types
  • Type theory
  • Unknown content

Keep exploring