Javatpoint Logo
Javatpoint Logo

How does 'void*' differ in C and C++?

Before learning the differentiating factor of void functions in C and C++ programming language, let us see a few examples and deeply understand the void function where it is used, use cases we can draw etc.

Void funThe void, as the name suggests, there is nothing it owes to any entity in programming. The void function, when called, will not return anything to the primary position; the control jumps to where the process is called after finishing the operation allowed in the process, which can either be calculation, recursion or printing anything to the display screens and then we will look at the play of pointers and examine How does 'void*' differ in C and C++?

C++ void function-1

C++ void function-2

Output:

//output_is_for_both_C++_codes_written_above
As we expect it to perform, the void function has returned the void to the central control.

C void Function

Output:

C void function print statement 1C void function print statement 1 perfection in programming in C."

How does 'void*' differ in C and C++?

A c programming language allows a void* pointer to be assigned to any

pointer type without a cast, whereas C++ does not. We have to typecast the void* pointer in C++ explicitly.

Let us look at the example below; the following is valid in C but not C++:

Similarly,

To make the above code compile in C++ as well, we have to use explicit casting, as shown below,







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA