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 - 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 ...
People also ask

What are data types in the C language?
Data types are the basic building blocks of the C programming language. They store the value of variables and tell the computer system how to interpret its value. A data type determines the type and size of data associated with variables.
🌐
shiksha.com
shiksha.com › home › it & software › it & software articles › programming articles › learn data types in c programming with examples
Learn Data Types in C Programming With Examples - Shiksha Online
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › learn data types in c programming with examples
Learn Data Types in C Programming With Examples - Shiksha Online
June 21, 2024 - We use the keyword ‘enum’ to declare new enumeration types in the C programming language. ... A popular example of enumerated data types is the days of the week. ... The void is just an empty data type that depicts that no value is available.
🌐
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 - It is advised to give the pointer a meaningful name that accurately describes its function. A void pointer is a unique type of pointer in the C language that may store the address of any data type.
🌐
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!

🌐
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
🌐
Quora
quora.com › Is-void-a-data-type
Is 'void' a data type? - Quora
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 ...
🌐
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!

🌐
University of Hawaii
ee.hawaii.edu › ~tep › EE160 › Book › chap5 › subsection2.1.3.1.html
5.3.1 Data Type void
In the function declaration and definition, we have indicated that the function does not return a value by using the data type void to show an empty type, i.e. no value. Similarly, when a function has no formal parameters, the keyword void is used in the function prototype and header to signify that there is no information passed to the function. Here is a simple program using a message printing function which takes a void parameter and returns type void: /* File: msg.c This program introduces data type void.
🌐
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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1303937 › why-are-double-and-void-data-types-but-long-is-not
Why are double and void data types but long is not? - Microsoft Q&A
Since functions that do return a value must declare the type of that value, void serves as the type for one that doesn't. Historically, this is significant because in the old days if you omitted the function return type it defaulted to int. If a function can take a pointer to any type of data, then it is declared as accepting a pointer to void.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › data-types-in-c
Data Types in C - GeeksforGeeks
C is a statically type language where each variable's type must be specified at the declaration and once specified, it cannot be changed. In this article, we will discuss the basic (primary) data types in C.
Published   June 30, 2015
🌐
Crasseux
crasseux.com › books › ctutorial › void.html
void - The GNU C Programming Tutorial - at Crasseux (?)
The void data type was introduced to make C syntactically consistent. The main reason for void is to declare functions that have no return value.
🌐
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.
🌐
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 ...
🌐
Unstop
unstop.com › home › blog › guide to data types in c (with detailed examples)
Guide To Data Types In C (With Detailed Examples) // Unstop
May 31, 2023 - Finally, it initialized by assigning ... runtime. In C programming, the void data type is an empty data type with no value and cannot be directly assigned to a variable....
🌐
GeeksforGeeks
geeksforgeeks.org › c language › void-pointer-c-cpp
void Pointer in C - GeeksforGeeks
A void pointer is a pointer that has no associated data type with it. A void pointer can hold an address of any type and can be typecasted to any type.
Published   July 17, 2014