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
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ void()
r/C_Programming on Reddit: void()
June 28, 2023 -

I am trying to learn C for the first time.

Can someone please explain to me when it is necessary to use the void function? I don't understand what is meant by it doesn't return a value.

Top answer
1 of 3
13
A return value is the data that the function evaluates to when it completes. If you have a function like this: int multiply(int x, int y) { return x * y; } Then you can write something like this: int result = multiply(6, 7); multiply will run, and the return value will be an int with the value of 42, which will then be assigned to the variable result. When you declare and define a function, you need to specify the return type, because the compiler needs to know how much space to use to store the return value, as well as making sure that you're not assigning the value to a mismatched type, or using it where a function expects a different type. In the case of a void function, you're telling the compiler that your function is not going to return any value at all. void say_hello(char *name) { printf("Hello, %s!\n", name); } In this case you just run the function, and it prints the message and then ends. There's no return value that the function gives you that you can use elsewhere in your program. ie. this would work: say_hello("George"); but this would not: int result = say_hello("George");
2 of 3
12
Void itself is not a function. It is used to define void functions, which are functions that don't return a value. You use it whenever you want to write a function that does not return a value. In some other languages, void functions are called procedures. For example, if you write a logging function, its purpose is to output data to a file. It doesn't calculate or read any information, so it doesn't need to return anything to the caller. The same keyword, void, is also used to define that a function does not take any parameters. So void hello(void) { /* ... */ } is a function that does not take any input parameters, and does not return any value. Finally, there are void pointers, but I think that's for another time.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_functions.php
C Functions
void means that the function does not have a return value. You will learn more about return values later in the next chapter ยท Inside the function (the body), add code that defines what the function should do ยท Declared functions are not executed ...
Discussions

c++ - What is the difference between function() and function(void)? - Software Engineering Stack Exchange
If a function is not meant to take any parameters, specify that by using void in the parameter list. ... 8.3.5 Functions [dcl.fct] ... 4 The parameter-declaration-clause determines the arguments that can be specified, and their processing, when the function is called. More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
June 11, 2015
ELI5: What is the purpose of void in C?
The other comments explain it well but here are some examples. void greet() { printf("Hello, world!\n"); } This is void because it does not return anything, it just does what it is told and doesn't report back. int add(int num1, int num2) { int sum = num1 + num2; return sum; } This has "int" where void would be, because it returns an int value. you would call this somewhere else in the code like so: int total = add(1,2); More on reddit.com
๐ŸŒ r/explainlikeimfive
36
0
March 8, 2024
Is it better to use C void arguments "void foo(void)" or not "void foo()"? - Stack Overflow
Means different things in C and C++! In C it means "could take any number of parameters of unknown types", and in C++ it means the same as foo(void). Variable argument list functions are inherently un-typesafe and should be avoided where possible. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Converting void pointers to function pointers.
In straight C it's technically not permitted, though the specification lists it as a common extension. Function pointers are not necessarily compatible with object or void pointers. In POSIX, this cast is permitted and valid since it's needed for dlsym(). More on reddit.com
๐ŸŒ r/C_Programming
4
6
October 30, 2016
๐ŸŒ
Florida State University
cs.fsu.edu โ€บ ~cop3014p โ€บ lectures โ€บ ch7 โ€บ index.html
Functions 2: Void (NonValue-Returning) Functions
Void functions are created and used just like value-returning functions except they do not return a value after the function executes. In lieu of a data type, void functions use the keyword "void." A void function performs a task, and then control returns back to the caller--but, it does
๐ŸŒ
ThoughtCo
thoughtco.com โ€บ definition-of-void-958182
What Is the Definition of "Void" in C and C++?
April 28, 2019 - When used in a function's parameter list, void indicates that the function takes no parameters. Void functions, also called nonvalue-returning functions, are used just like value-returning functions except void return types do not return a value ...
๐ŸŒ
Quora
quora.com โ€บ Why-do-we-use-void-in-C-programming-functions-instead-of-format-specifiers
Why do we use void in C programming functions, instead of format specifiers? - Quora
Answer (1 of 7): Void is one of those language smells in C. They tried to make everything functions, but not variables and constants which are also functions. Routines that donโ€™t return anything are not functions. C is really confused over functions. https://www.quora.com/Does-a-function-always-...
Top answer
1 of 2
38

C and C++ are different in this respect.

C 2011 Online Standard

6.7.6.3 Function declarators (including prototypes)
...
10 The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
...
14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.145)

In short, an empty parameter list in a function declaration indicates that the function takes an unspecified number of parameters, while an empty parameter list in a function definition indicates that the function takes no parameters.

T foo( void ); // declaration, foo takes no parameters
T bar();       // declaration, bar takes an *unspecified* number of parameters

T foo( void ) { ... } // definition, foo takes no parameters
T bar() { ... }       // definition, bar takes no parameters

As far as C is concerned, you should never use an empty identifier list in a function declaration or definition. If a function is not meant to take any parameters, specify that by using void in the parameter list.

Online C++ standard

8.3.5 Functions [dcl.fct]
...
4 The parameter-declaration-clause determines the arguments that can be specified, and their processing, when the function is called. [ Note: the parameter-declaration-clause is used to convert the arguments specified on the function call; see 5.2.2. โ€” end note ] If the parameter-declaration-clause is empty, the function takes no arguments. A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. Except for this special case, a parameter shall not have type cv void. If the parameter-declaration-clause terminates with an ellipsis or a function parameter pack (14.5.3), the number of arguments shall be equal to or greater than the number of parameters that do not have a default argument and are not function parameter packs. Where syntactically correct and where โ€œ...โ€ is not part of an abstract-declarator, โ€œ, ...โ€ is synonymous with โ€œ...โ€. [Example: the declaration
    int printf(const char*, ...);
declares a function that can be called with varying numbers and types of arguments.
    printf("hello world");
    printf("a=%d b=%d", a, b);
However, the first argument must be of a type that can be converted to a const char* โ€” end example ] [ Note: The standard header <cstdarg> contains a mechanism for accessing arguments passed using the ellipsis (see 5.2.2 and 18.10). โ€” end note ]

In the case of C++, an empty parameter list in either a declaration or a definition indicates that the function takes no arguments, and is equivalent to using a parameter list of void.

2 of 2
45

In C, a function with an empty parameter list () can take anything for its arguments. Literally anything. This is usually used to implement a function which can take a variable number of arguments, though these days it's considered preferable to use the more explicit ellipsis syntax (...) for these functions.

In C, a function with the parameter list (void) explicitly takes nothing for its arguments. That means the compiler can actually tell you you've made a mistake if you try to pass something.

In C++, these function declarations are equivalent. A blank parameter list means "no parameters" the same as void does.

Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ void-pointer-c-cpp
void Pointer in C - GeeksforGeeks
void pointers in C are used to implement generic functions in C.
Published ย  3 weeks ago
๐ŸŒ
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!

๐ŸŒ
Quora
quora.com โ€บ How-do-you-create-and-call-a-void-function-without-returning-anything-void-in-C-programming-language
How to create and call a void function without returning anything (void) in C programming language - Quora
Answer (1 of 3): The answer is simple, define a void function and return nothing.. void myfunchaha(){ printf(โ€œI will return nothing hahahaโ€); // no need for return } That's it but if you want to know how this works on the background. Let me explain Guillermo's answer a bit more deeper. Sinc...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-void-keyword-in-c
What is the void keyword in C?
The literal meaning of void is empty or blank. In C, void can be used as a data type that represents no data. ... Return type of a function that returns nothing.
๐ŸŒ
Quora
quora.com โ€บ In-C-programming-what-does-writing-void-do-in-the-function-int-main-void-printf-Hello-world-return-0
In C programming, what does writing 'void' do in the function: int main (void) {printf ('Hello world'); return 0;}? - Quora
Answer (1 of 3): It is an optional part of more modern versions of C to indicate that the function takes no arguments. In very old versions of C specifying the arguments in a function prototype was optional so you needed to use void to explicitly ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ cpp โ€บ void-cpp
void (C++) | Microsoft Learn
August 5, 2025 - As a matter of style, the C++ Core Guidelines recommend you don't use void to specify an empty formal parameter list. For more information, see C++ Core Guidelines NL.25: Don't use void as an argument type. // void.cpp void return_nothing() { // A void function can have a return with no argument, // or no return statement.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Void_type
Void type - Wikipedia
2 weeks ago - 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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ return-from-void-functions-in-cpp
Return From Void Functions in C++ - GeeksforGeeks
January 27, 2023 - The above code explains how void() can actually be useful to return void functions without giving errors. 3) A void() can return a void value: A void() cannot return a value that can be used. But it can return a value that is void without giving an error. For example, ... // C++ code to demonstrate void() // returning a void value #include <iostream> using namespace std; // Driver void() returning a void value void test() { cout << "Hello"; // Returning a void value return (void)"Doesn't Print"; } // Driver Code int main() { test(); return 0; }
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 38143-using-void-function.html
using a Void Function?
April 17, 2003 - Originally posted by Smoot This is for a class, so our handout specifically says to use void.... void drawRect (int width, int height, char character) If this isnt going to work, what are some examples of why you would use void? Your function will work on its own, just don't put it as a parameter to a printf statement.
๐ŸŒ
Learn C++
learncplusplus.org โ€บ home โ€บ c++ โ€บ what is a void function in the c programming language?
What is A Void Function In The C Programming language?
September 3, 2022 - In C and C++ programing, the void term means โ€œno value is returnedโ€. In math, a function returns a value, i.e. y = f (x); Here f(x) is a function that works with variable x and y is the output of this function.
๐ŸŒ
Yale University
cs.yale.edu โ€บ homes โ€บ aspnes โ€บ pinewiki โ€บ C(2f)Functions.html
C/Functions
The ints scattered about specify ... types will often convert automatically) to detect type mismatches. If you want to define a function that doesn't return anything, declare its return type as void....
Top answer
1 of 6
339
void foo(void);

That is the correct way to say "no parameters" in C, and it also works in C++.

But:

void foo();

Means different things in C and C++! In C it means "could take any number of parameters of unknown types", and in C++ it means the same as foo(void).

Variable argument list functions are inherently un-typesafe and should be avoided where possible.

2 of 6
105

There are two ways for specifying parameters in C. One is using an identifier list, and the other is using a parameter type list. The identifier list can be omitted, but the type list can not. So, to say that one function takes no arguments in a function definition you do this with an (omitted) identifier list

void f() {
    /* do something ... */
}

And this with a parameter type list:

void f(void) {
    /* do something ... */
}

If in a parameter type list the only one parameter type is void (it must have no name then), then that means the function takes no arguments. But those two ways of defining a function have a difference regarding what they declare.

Identifier lists

The first defines that the function takes a specific number of arguments, but neither the count is communicated nor the types of what is needed - as with all function declarations that use identifier lists. So the caller has to know the types and the count precisely before-hand. So if the caller calls the function giving it some argument, the behavior is undefined. The stack could become corrupted for example, because the called function expects a different layout when it gains control.

Using identifier lists in function parameters is deprecated. It was used in old days and is still present in lots of production code. They can cause severe danger because of those argument promotions (if the promoted argument type do not match the parameter type of the function definition, behavior is undefined either!) and are much less safe, of course. So always use the void thingy for functions without parameters, in both only-declarations and definitions of functions.

Parameter type list

The second one defines that the function takes zero arguments and also communicates that - like with all cases where the function is declared using a parameter type list, which is called a prototype. If the caller calls the function and gives it some argument, that is an error and the compiler spits out an appropriate error.

The second way of declaring a function has plenty of benefits. One of course is that amount and types of parameters are checked. Another difference is that because the compiler knows the parameter types, it can apply implicit conversions of the arguments to the type of the parameters. If no parameter type list is present, that can't be done, and arguments are converted to promoted types (that is called the default argument promotion). char will become int, for example, while float will become double.

Composite type for functions

By the way, if a file contains both an omitted identifier list and a parameter type list, the parameter type list "wins". The type of the function at the end contains a prototype:

void f();
void f(int a) {
    printf("%d", a);
}

// f has now a prototype. 

That is because both declarations do not say anything contradictory. The second, however, had something to say in addition. Which is that one argument is accepted. The same can be done in reverse

void f(a) 
  int a;
{ 
    printf("%d", a);
}

void f(int);

The first defines a function using an identifier list, while the second then provides a prototype for it, using a declaration containing a parameter type list.