To create (often referred to as declare) a function, specify the name of the function, followed by parentheses (): void means that the function does not have a return value. You will learn more about return values later in the next chapter. Declared functions are not executed immediately.
Although we showed examples of functions that had return-type void, we did not discuss what this meant. In this lesson, we’ll explore functions with a return type of void.
We cannot return values but there is something we can surely return from voidfunctions. Voidfunctions do not have a return type, but they can do return values.
You cannot dereference a void * or do pointer arithmetic with it; you must convert it to a pointer to a complete data type first. void * is often used in places where you need to be able to work with different pointer types in the same code. One commonly cited example is the library function qsort:
A function with void result type ends either by reaching the end of the function or by executing a return statement with no returned value. The void type may also replace the argument list of a function prototype to indicate that the function takes no arguments.
When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."
Voidfunctions 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, voidfunctions use the keyword "void."
The `void` keyword plays a significant role in defining specific functions that perform tasks without expecting to return a value. By effectively utilizing voidfunctions, you can enhance code clarity and maintainability, especially when dealing with actions that don't involve a return type.
Learn how to create a voidfunction in Python! This tutorial explains defining functions without a return value, their use cases, and practical examples.
Void functions are functions that perform an action but do not return any value. They might print something, modify a global variable, or write to a file, but they do not use the return keyword.