what is void data type
Void is an empty data type normally used as a return type in C/C++, C#, Java functions/methods to declare that no value will be return by the function.
The another use of void is to declare the pointer in C/C++ whe It is not sure that what data type will be addressed by the pointer.
eg:
void *p;
Here p can hold the address of int or float or char or long int or double.
The voiddata type is used when a function doesn't return any value, and/or when it has no parameters at all. Pointer type 'void *' is a generic pointer.A void pointer is used when it needs to be assigned to different data types later on in a program. Since it avoids type checking, void pointers should be used with care.
Void - is empty data type in C
void is type of pointer that usually means that you can make it point to any data type. When you make a pointer point to somewhere its data type should match with the place where you want it to point. When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.
Data-type void has some special features:- it doesn't have values- it doesn't have size- you cannot declare variables with it- void *pointers cannot be dereferenced
void as function return-type means no return value void as function parameter means no parameter void * as pointer type means generic pointer
doesn't return the value.
The voiddata type is used when a function doesn't return any value, and/or when it has no parameters at all. Pointer type 'void *' is a generic pointer.A void pointer is used when it needs to be assigned to different data types later on in a program. Since it avoids type checking, void pointers should be used with care.
void isn't an actual data-type, preemptive(?) or otherwise.
Void - is empty data type in C
void is type of pointer that usually means that you can make it point to any data type. When you make a pointer point to somewhere its data type should match with the place where you want it to point. When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.
Data-type void has some special features:- it doesn't have values- it doesn't have size- you cannot declare variables with it- void *pointers cannot be dereferenced
Void Pointer is a General purpose pointer ,that does not have any data type associated with it and can store address of any type of variable. Declaration: void * pointer_name;
void as function return-type means no return value void as function parameter means no parameter void * as pointer type means generic pointer
Pick any three: int, char, long, void, char *, void *
Void means there is no data type. So if you have a void function it does not return a value (and attempting to do so will cause an error) whereas a non-void function (ex. int, long, String, bool, etc) will return a value of that type.
The void type has only one purpose: to specify the return type of a function that has no return value. In this case void simply means no type. The only other usage is when used as a pointer to void (void*), which simply means a pointer type that can refer to any type of object. If the pointer is non-null, it must be cast to a specific type before it can be dereferenced.
The question posed is a bit difficult to answer as there are no context specific clues (are we talking C/C++ here, or something more general such as object references in Java?), so an answer relating to C is given. Many times when writing a program it becomes necessary to pass a reference to a piece of data to a function, or perhaps to store a reference to a piece of data -- especially when writing a data structure that stores references to many different data (of many different types). In such a case the easiest way is to create a void pointer reference (void*). Now "casting the pointer" in order to correctely dereference the data is simply a matter of knowing the data type you are casting to, and indicating that it is a reference to a piece of data of that type. For example, suppose you have a structure called foo, that contains a field called bar, then: void printbar(void* myfoo) { printf("Bar = %s\n", (struct foo*)myfoo->bar); } should solve your problem. In this example you are indicating that the void pointer myfoo (which holds a memory reference) should be cast to a pointer that holds a memory reference to a piece of data of the type stuct foo.