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
2010-08-15 14:13:01
thanx it will help
suhel
2010-08-15 14:17:50
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
2010-08-15 15:53:18