Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data".

Hence, you can declare a routine which does not return a value as:

void MyRoutine();

But, you cannot declare a variable like this:

void bad_variable;

However, when used as a pointer, then it has a different meaning:

void* vague_pointer;

This declares a pointer, but without specifying which data type it is pointing to.

Answer from James Curran on Stack Overflow

Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data".

Hence, you can declare a routine which does not return a value as:

void MyRoutine();

But, you cannot declare a variable like this:

void bad_variable;

However, when used as a pointer, then it has a different meaning:

void* vague_pointer;

This declares a pointer, but without specifying which data type it is pointing to.

Answer from James Curran on Stack Overflow
Top answer
1 of 3
106

Void is considered a data type (for organizational purposes), but it is basically a keyword to use as a placeholder where you would put a data type, to represent "no data".

Hence, you can declare a routine which does not return a value as:

void MyRoutine();

But, you cannot declare a variable like this:

void bad_variable;

However, when used as a pointer, then it has a different meaning:

void* vague_pointer;

This declares a pointer, but without specifying which data type it is pointing to.

2 of 3
38

Yes, void is a type. Whether it's a data type depends on how you define that term; the C standard doesn't.

The standard does define the term "object type". In C99 and earlier; void is not an object type; in C11 and later, it is. In all versions of the standard, void is an incomplete type. What changed in C11 is that incomplete types are now a subset of object types. This is just a change in terminology. (The other kind of type is a function type.)

C99 6.2.6 paragraph 19 says:

The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

The C11 standard changes the wording slightly:

The void type comprises an empty set of values; it is an incomplete object type that cannot be completed.

This reflects C11's change in the definition of "object type" to include incomplete types. It doesn't really change anything about the nature of type void.

The void keyword can also be used in some other contexts:

  • As the only parameter type in a function prototype, as in int func(void), it indicates that the function has no parameters. (C++ uses empty parentheses for this, but they mean something else in C (prior to C23).)

  • As the return type of a function, as in void func(int n), it indicates that the function returns no result.

  • void* is a pointer type that doesn't specify what it points to.

In principle, all of these uses refer to the type void, but you can also think of them as just special syntax that happens to use the same keyword.

🌐
Wikipedia
en.wikipedia.org › wiki › Void_type
Void type - Wikipedia
2 weeks ago - 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.
🌐
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!

🌐
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. For example, compare function which is used in qsort(). void pointers used along with Function pointers of type void (*)(void) point to the functions that take any arguments and ...
Published   July 17, 2014
🌐
Reddit
reddit.com › r/c_programming › eli5: void in c
r/C_Programming on Reddit: ELI5: 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 › What-is-the-difference-between-a-void-and-a-data-type-in-the-programming-language-C
What is the difference between a void and a data type in the programming language C? - Quora
Answer: void means that while it is legal to put a data type there, the programmer does not want to put a data type there. Often this is used for return type. A data type describes some data. void foo(); int bar(); float zz(); are examples of ...
🌐
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 ...
Find elsewhere
🌐
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. Consider the code snippet below, which uses void as a pointer declaration. ... Note: The void pointer cannot be dereferenced directly. It has to be type cast to a data type before being dereferenced.
🌐
Crasseux
crasseux.com › books › ctutorial › void.html
void - The GNU C Programming Tutorial - at Crasseux (?)
Although the data returned by a function can legally be ignored by the function calling it, the void data type was introduced by the ANSI standard so that C compilers can issue warnings when an integer value is not returned by a function that is supposed to return one.
🌐
University of Hawaii
ee.hawaii.edu › ~tep › EE160 › Book › chap5 › subsection2.1.3.1.html
5.3.1 Data Type void
/* File: msg.c This program introduces data type void. */ ... /* Function prints a message. */ void printmsg(void) { printf("****HOME IS WHERE THE HEART IS****\n"); } No parameters are required for the function, printmsg(), and it returns no value; it merely prints its message. In the function call in main(), parentheses must be used without any arguments. Observe that no return statement is present in printmsg(). When a function is called, the body is executed and, when the end of the body is reached, program control returns to the calling function.
🌐
Quora
quora.com › Is-void-a-data-type
Is 'void' a data type? - Quora
Answer (1 of 6): In C, C++ and similar languages, [code ]void[/code] tends to be a special case in the type system. It is a type, but it’s one that generally appears as part of another type—a function type involving [code ]void[/code] or perhaps a pointer ([code ]void*[/code]). This means ...
🌐
Swiftorial
swiftorial.com › tutorials › data types › void data type
Void Data Type in C
August 22, 2025 - The void data type is commonly used in the following scenarios: Declaring functions that do not return a value. Creating generic pointers that can point to any data type. Defining functions that do not accept any arguments. The void data type is an essential feature of the C programming language.
🌐
Fresh2Refresh
fresh2refresh.com › home › c programming tutorial › c interview questions › what is void in c?
What is void in C? | C Interview Questions | Fresh2Refresh.com
October 15, 2020 - Void is an empty data type that has no value. We use void data type in functions when we don’t want to return any value to the calling function.
🌐
Quora
quora.com › What-is-void-datatype-in-c
What is void datatype in c? - Quora
Answer (1 of 2): Responding, based on reading your question as > “What is void in C” Every programming language needs a member for referencing objects it uses to execute a piece of logic. And these objects need to be stored in memory During the context of execution.
🌐
freeCodeCamp
freecodecamp.org › news › data-types-in-c-integer-floating-point-and-void-explained
Data Types in C - Integer, Floating Point, and Void Explained
February 1, 2020 - A pointer of type void represents the address of an object, but not its type. For example, a memory allocation function `void malloc( size_t size);` returns a pointer to void which can be casted to any data type.
🌐
Unstop
unstop.com › home › blog › void pointer in c explained in detail with code examples
Void Pointer In C Explained In Detail With Code Examples // Unstop
March 1, 2024 - They can point to any sort of object, including user-defined types, floats, characters, and integers. You cannot, however, immediately dereference or use pointer arithmetic on them since the type is unknown.
🌐
Blogger
girfahelp.blogspot.com › 2017 › 06 › define-void-data-type-and-write-any.html
Girfa : Student Help: Define void data type and write any three use of it.
1. When used as a function return type: the void keyword specifies that the function does not return a value. ... 2. When used for a function's parameter list: void specifies that the function takes no parameters. int sum(void) ... 3. When used in the declaration of a pointer: void specifies ...
🌐
Code with C
codewithc.com › code with c › blog › understanding void type in c programming
Understanding Void Type In C Programming - Code With C
January 12, 2024 - Now, this is where it gets interesting. You can use void as a parameter to signify that the function takes no parameters. It’s like a mysterious box that needs no input but still does its magic when called upon.
Top answer
1 of 5
11

In C language the void type has been introduced with the meaning of 'don't care' more than 'null' or 'nothing', and it's used for different scopes.

The void keyword can reference a void type, a reference to void, a void expression, a void operand or a void function. It also explicitly defines a function having no parameters.

Let's have a look at some of them.


The void type

First of all void object exists and have some special properties, as stated in ISO/IEC 9899:2017, §6.2.5 Types:

  1. The void type comprises an empty set of values; it is an incomplete object type that cannot be completed.

Pointers

The more useful reference to void, or void *, is a reference to an incomplete type, but itself is well defined, and then is a complete type, have a size, and can be used as any other standard variable as stated in ISO/IEC 9899:2017, §6.2.5 Types:

  1. A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.

    Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements.

    All pointers to structure types shall have the same representation and alignment requirements as each other.

    All pointers to union types shall have the same representation and alignment requirements as each other.

    Pointers to other types need not have the same representation or alignment requirements.


Casting to void

It can be used as cast to nullify an expression, but allowing the completion of any side effect of such expression. This concept is explained in the standard at ISO/IEC 9899:2017, §6.3 Conversions, §6.3.2.2 void:

  1. The (nonexistent) value of a void expression (an expression that has type void) shall not be used in any way, and implicit or explicit conversions (except to void) shall not be applied to such an expression.

    If an expression of any other type is evaluated as a void expression, its value or designator is discarded. (A void expression is evaluated for its side effects.)

A practical example for the casting to void is its use to prevent warning for unused parameters in function definition:

int fn(int a, int b)
{
    (void)b;    //This will flag the parameter b as used 

    ...    //Your code is here

    return 0;
}

The snippet above shows the standard practice used to mute compiler warnings. The cast to void of parameter b acts as an effective expression that don't generate code and marks b as used preventing compiler complains.


void Functions

The paragraph §6.3.2.2 void of the standard, covers also some explanation about void functions, that are such functions that don't return any value usable in an expression, but functions are called anyway to implement side effects.


void pointers properties

As we said before, pointers to void are much more useful because they allow to handle objects references in a generic way due to their property explained in ISO/IEC 9899:2017, §6.3.2.3 Pointers:

  1. A pointer to void may be converted to or from a pointer to any object type.

    A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.

As practical example imagine a function returning a pointer to different objects depending on input parameters:

enum
{
    FAMILY,     //Software family as integer
    VERSION,    //Software version as float
    NAME        //Software release name as char string
} eRelease;

void *GetSoftwareInfo(eRelease par)
{
    static const int   iFamily  = 1;
    static const float fVersion = 2.0;
    static const *char szName   = "Rel2 Toaster";

    switch(par)
    {
        case FAMILY:
            return &iFamily;
        case VERSION:
            return &fVersion;
        case NAME:
            return szName;
    }
    return NULL;
}

In this snippet you can return a generic pointer that can be dependent on input par value.


void as functions parameter

The use of void parameter in functions definitions was introduced after the, so called, ANSI-Standard, to effectively disambiguate functions having variable number of arguments from functions having no arguments.

From standard ISO/IEC 9899:2017, 6.7.6.3 Function declarators (including prototypes):

  1. The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.

Actual compilers still support function declaration with empty parenthesis for backward compatibility, but this is an obsolete feature that will eventually be removed in future release of standard. See Future directions - §6.11.6 Function declarators:

  1. The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.

Consider the following example:

int foo();         //prototype of variable arguments function (backward compatibility)
int bar(void);     //prototype of no arguments function
int a = foo(2);    //Allowed
int b = foo();     //Allowed
int c = bar();     //Allowed
int d = bar(1);    //Error!

Now resembling your test, if we call the function bar as follows:

int a = 1;
bar((void)a);

Triggers an error, because casting to void an object doesn't null it. So you are still trying to pass a void object as parameter to a function that don't have any.


Side effects

As requested this is a short explain for side effects concept.

A side effect is whichever alteration of objects and values derived from the execution of a statement, and which are not the direct expected effect.

int a = 0;
(void)b = ++a;

In the snippet above the void expression lose the direct effect, assigning b, but as side effect increase the value of a.

The only reference, explaining the meaning, in the standard can be found in 5.1.2.3 Program execution:

  1. Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment.

    Evaluation of an expression in general includes both value computations and initiation of side effects.

2 of 5
11

void is a type. Per C 2018 6.2.5 19, the type has no values (the set of values it can represent is empty), it is incomplete (its size is unknown), and it cannot be completed (its size cannot be known).

Regarding extern void a;, this does not define an object. It declares an identifier. If a were used in an expression (except as part of a sizeof or _Alignof operator), there would have to be a definition for it somewhere in the program. Since there cannot a definition of void object in strictly conforming C, a cannot be used in an expression. So I think this declaration is allowed in strictly conforming C but is not useful. It might be used in C implementations as an extension that allows getting the address of an object whose type is not known. (For example, define an actual object a in one module, then declare it as extern void a; in another module and use &a there to get its address.)

The declaration of functions with (void) as a parameter list is a kludge. Ideally, () might be used to indicate a function takes no parameters, as is the case in C++. However, due to the history of C, () was used to mean an unspecified parameter list, so something else had to be invented to mean no parameters. So (void) was adopted for that. Thus, (void) is an exception to the rules that would say (int) is for a function taking an int, (double) is for a function taking a double, and so on—(void) is a special case meaning that a function takes no parameters, not that it takes a void.

In foo((void) a), the cast does not make the value “not exist.” It converts a to the type void. The result is an expression of type void. That expression “exists,” but it has no value and cannot be used in an expression, so using it in foo((void) a) results in an error message.