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 ...
🌐
Rebus Community
press.rebus.community › programmingfundamentals › chapter › void-data-type
Void Data Type – Programming Fundamentals
December 15, 2018 - The void data type, similar to ... earlier, is the data type for the result of a function that returns normally, but does not provide a result value to its caller.[1] The void data type has no values and no operations.
🌐
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 › 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 ...
🌐
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.
🌐
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!

Find elsewhere
🌐
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-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.
🌐
Codefinity
codefinity.com › courses › v2 › 23515a83-24c1-4300-93aa-17f6fc71455f › e1b0bd58-bbba-4a3c-bff7-0ec91aaf3f59 › 6c63d499-53df-4886-8aaf-a2256d790d48
Learn Void Data Type | Other Data Types and Concepts
In this case we can use void data type. The void data type in programming signifies the absence of any value or type. It can be used in many different ways but for the function it is usually used to indicate that a function does not return any value.
🌐
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
🌐
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.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › The-Void-Type.html
The Void Type (GNU C Language Manual)
Next: Other Data Types, Previous: Complex Data Types, Up: Primitive Data Types [Contents][Index] The data type void is a dummy—it allows no operations. It really means “no value at all.” When a function is meant to return no value, we write void for its return type.
🌐
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 ...
🌐
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 ...
🌐
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.
🌐
BYJUS
byjus.com › gate › void-pointer-in-c
Void Pointer in C
August 1, 2022 - The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer.
🌐
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 - 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 ...
🌐
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.