tags:

views:

135

answers:

1

Hi, Can I know if void is data type in "C"? what type of values it can store, if we have int, float, char etc to store the values why is void needed?

+8  A: 

It's 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 declare a pointer, but without specifying what data type it is pointing to.

James Curran
thanx it will help
suhel
and since you don't specify what a void pointer points to, you can't perform math on it. The compiler wouldn't know how far to move the pointer to get to the next item in memory.
fennec