Basically it means "nothing" or "no type"

There are 3 basic ways that void is used:

  1. Function argument: int myFunc(void) -- the function takes nothing.

  2. Function return value: void myFunc(int) -- the function returns nothing

  3. Generic data pointer: void* data -- 'data' is a pointer to data of unknown type, and cannot be dereferenced

Note: the void in a function argument is optional in C++, so int myFunc() is exactly the same as int myFunc(void), and it is left out completely in C#. It is always required for a return value.

Answer from Gerald on Stack Overflow

Basically it means "nothing" or "no type"

There are 3 basic ways that void is used:

  1. Function argument: int myFunc(void) -- the function takes nothing.

  2. Function return value: void myFunc(int) -- the function returns nothing

  3. Generic data pointer: void* data -- 'data' is a pointer to data of unknown type, and cannot be dereferenced

Note: the void in a function argument is optional in C++, so int myFunc() is exactly the same as int myFunc(void), and it is left out completely in C#. It is always required for a return value.

Answer from Gerald on Stack Overflow
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Void_type
Void type - Wikipedia
2 weeks ago - 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.
Top answer
1 of 2
3
Void is used when there is no return, for example, You could make a constructor like public String onColorSwitch(String color) { return color; } but if you aren't going to return anything, then you could use, public void onColor() { }
2 of 2
1
Void basically means "no type", "no value" or "empty". Void is most commonly used in functions and methods. If you have worked with functions before, this might help you understand better: java\main.java functions f = new functions(); String message = "Hello world!"; f.print_func(message); java\functions.java public void print_func(String var) { System.out.println(var); } In our main class we make a string with the value "Hello world!" and then call the function print_func with that message as the argument. The function takes the argument and prints it out and returns nothing back to the main class because there is nothing that functions calculated or created -- it just printed a message to the user. This is why we declared our function as a void -- it passes nothing back to it's caller once it's finished running. An example where void shouldn't be used: java\main.java functions f = new functions(); int number = 5; int new_number = 0; new_number = f.calc_func(number); System.out.println(new_number); java\functions.java public int calc_func(int var) { int new_number = var * 2; return new_number; } In this example, our function takes a number (in this case the number "5") and calculates it's double (5 x 2 = 10 in this example). Once the function has completed this calculation, our main class needs to know what was calculated, so the function needs to return this value back to it's caller. The main class get's the value and stores it in new_number which is then printed out to the user. So whenever you create a function or method in java, you need to tell java the type that is being returned (int, String, etc). If nothing is returned, then you need to tell this by using void where applicable. Void can also be used as a pointer for unknown types, but that's a bit advanced. Hope this helps! :)
๐ŸŒ
Lenovo
lenovo.com โ€บ home
What is Void? A Comprehensive Overview | Lenovo US
In computer programming, "void" serves several purposes. When used as a function return type, it indicates that the function does not return a value. In pointer declarations, "void" means the pointer can point to any data type, making it versatile. When "void" appears in a function's parameter ...
๐ŸŒ
ThoughtCo
thoughtco.com โ€บ definition-of-void-958182
What Is the Definition of "Void" in C and C++?
April 28, 2019 - The void function accomplishes its task and then returns control to the caller. The void function call is a stand-alone statement. For example, a function that prints a message doesn't return a value.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ void
void Keyword in Java: Usage & Examples
Here, the greet method takes a String parameter name and prints a greeting message. The method is declared with a void return type, indicating it does not return any value.
Find elsewhere
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ cpp โ€บ void-cpp
void (C++) | Microsoft Learn
When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."
๐ŸŒ
C-programming-simple-steps
c-programming-simple-steps.com โ€บ what-is-void.html
What is void in C - C Programming
Master C programming in simple steps! Newbie or advanced you can do this in simple steps! Here are the tutorials and examples that will show you how.
๐ŸŒ
Lenovo
lenovo.com โ€บ home
What is Void? A Comprehensive Overview | Lenovo IN
In computer programming, "void" serves several purposes. When used as a function return type, it indicates that the function does not return a value. In pointer declarations, "void" means the pointer can point to any data type, making it versatile. When "void" appears in a function's parameter ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-void-keyword-in-c
What is the void keyword in C?
Note: In C, foo() is different from foo(void). foo() means that the function takes an unspecified number of arguments. foo(void) is used for a function that takes no arguments. Generic pointer declaration that has no type specified with it.
๐ŸŒ
Quora
quora.com โ€บ What-is-a-void-in-a-programming-language-Is-void-a-function-in-programming
What is a void in a programming language? Is void a function in programming? - Quora
Answer (1 of 5): Some languages make a big syntactic distinction between subroutines (โ€œcallablesโ€ that return control to callsite when complete but do not return a value) and functions (โ€œcallablesโ€ that are like subroutines but also return a value to the callsite in addition to flow controls).
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_keyword_void.asp
Java void Keyword
The void keyword specifies that a method should not have a return value. Tip: If you want a method to return a value, you can use a primitive data type (such as int, char, etc.) instead of void, and use the return keyword inside the method:
๐ŸŒ
Reddit
reddit.com โ€บ r/explainlikeimfive โ€บ eli5: what is the purpose of void in c?
r/explainlikeimfive on Reddit: ELI5: What is the purpose of void in C?
March 8, 2024 -

I just began studying C and I cannot, for the life of me, understand void.

I have read and listened to many people say "It does not return a value". Ok? What is a value? Why wouldn't we want to return it? What is the difference between "void main" and "int main"? Can we just use int for everything and ignore void altogether?

In what situations is void used? In what situations is void better? etc. Please help I don't get it at all!

๐ŸŒ
Rebus Community
press.rebus.community โ€บ programmingfundamentals โ€บ chapter โ€บ void-data-type
Void Data Type โ€“ Programming Fundamentals
December 15, 2018 - The void data type is typically used in the definition and prototyping of functions to indicate that either nothing is being passed in and/or nothing is being returned. ... A data type that has no values or operators and is used to represent ...
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 5279-what-is-void-in-java-and-what-is-it-used-for
[JavaScript] - What is Void in Java and What is it Used | SheCodes
The `void` keyword in Java is a reserved type used to specify that a method does not return any data type. ... Write a function that takes in a single number. It should return the string even if the number is even, and the string odd if the ...
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2756726 โ€บ what-is-the-use-of-void-before-the-function
what is the use of void before the function? | Sololearn: Learn to code for FREE!
In C and C++ programming languages, `void` is used as a return type for a function that does not return a value. When a function is declared with `void` as its return type, it means that the function does not return any value to the caller.
๐ŸŒ
Learn C++
learncpp.com โ€บ cpp-tutorial โ€บ void
4.2 โ€” Void โ€“ Learn C++
Void is the easiest of the data types to explain. Basically, void means โ€œno typeโ€! Void is our first example of an incomplete type. An incomplete type is a type that has been declared but not yet defined. The compiler knows about the existence of such types, but does not have enough information ...
๐ŸŒ
Youth4work
youth4work.com โ€บ talent โ€บ object oriented programming โ€บ forum โ€บ what is meaning of void
What is meaning of Void
July 8, 2018 - ... The void is a keyword and a data type which means null. Whenever the data type void is used it will not return any value after implementing it. It is mainly used with main function and main is also a keyword.