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. The C language standard does not guarantee that the different pointer types have the same size or alignment.
🌐
Shaalaa
shaalaa.com › question-bank-solutions › what-is-the-importance-of-void-data-type_227831
What is the importance of void data type? - Computer Science | Shaalaa.com
June 25, 2021 - Short/Brief Note · The void type has two important purposes: To indicate the function does not return a value. To declare a generic pointer. shaalaa.com · Report Error Is there an error in this question or solution?
🌐
Rebus Community
press.rebus.community › programmingfundamentals › chapter › void-data-type
Void Data Type – Programming Fundamentals
December 15, 2018 - Many programming languages need a data type to define the lack of return value to indicate that nothing is being returned. The void data type is typically used in the definition and prototyping of functions to indicate that either nothing is ...
🌐
University of Hawaii
ee.hawaii.edu › ~tep › EE160 › Book › chap5 › subsection2.1.3.1.html
5.3.1 Data Type void
However, the void declaration makes the nature of the function explicit to someone reading the code and may allow the compiler to generate more efficient object code. Previous: 5.3 Scalar Data Types Up: 5.3 Scalar Data Types Next: 5.3.2 Enumeration Previous Page: 5.3 Scalar Data Types Next ...
🌐
Engineering LibreTexts
eng.libretexts.org › bookshelves › computer science › programming and computation fundamentals › programming fundamentals (busbee and braunschweig) › 3: functions
3.7: Void Data Type - Engineering LibreTexts
July 7, 2020 - Many programming languages need a data type to define the lack of return value to indicate that nothing is being returned. The void data type is typically used in the definition and prototyping of functions to indicate that either nothing is ...
Find elsewhere
🌐
Quora
quora.com › What-is-void-data-type
What is void data type? - Quora
Answer (1 of 17): Maybe I’m the wrong person to answer that, since I’m not a developer. But I did learn programming basics like 20 years ago and still use some of that knowledge today. So, let me answer this the way I see it. A way it seems, nobody or barely anyone sees it today.
🌐
LearnPick
learnpick.in › home › questions & answers › computer science in class 11 - 12 › solutions with answers
What is the use of void data type? - Find 3 Answers & Solutions ...
Basically all the computation are done within the function and you've nothing to return the caller, the void keyword specifies that the function does not return a value. When used for a function's parameter list, void specifies that the function takes no parameters.
🌐
Sarthaks eConnect
sarthaks.com › 3509253 › what-is-the-purpose-of-the-void-data-type
What is the purpose of the void data type? - Sarthaks eConnect | Largest Online Education Community
LIVE Course for free · The void data type in C is a special type that represents the absence of a value. It is primarily used in three different contexts:
🌐
Sololearn
sololearn.com › en › Discuss › 2153205 › what-are-the-benefits-of-using-void-data-types-for-functions-pointers-and-more
What are the benefits of using void data types for functions,pointers and more? | Sololearn: Learn to code for FREE!
Void functions don't return a type. They can be used in scenarios when you want to do/change something. But don't want to return anything. Such as: void printOneToTen(){ for(int i = 0; i < 10; i++){ cout << i; } } (C++ Code) In this case I wanted ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Please clarify my understanding of the data type 'void' - Programming - Arduino Forum
February 3, 2014 - I have done a lot of research on this, looked at many explanations relating to both Arduino and C++. I've looked at text explanations and video tutorials both. Read over the Arduino.cc reference pages. I've searched this…
🌐
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 ...
🌐
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.
🌐
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 › 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 ...
🌐
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.
The data type void actually refers to an object that does not have a value of any type. Void is also used to indicate when a function does not return a value or no argument. Such a function is used for its side effect and not for its value. In the function declaration and definition, we have ...