program 1:
int main()
{
void v=8;
printf("v=%d\n",v);
}
program 2:
int main()
{
void *v=8;
printf("*v=%u\n",*v);
printf("v=%u\n",v);
}
compilation error on program 1:
**error**: variable or field ‘v’ declared void void v=0;
compilation errr on program 2:
**error**:invalid use of void expression printf("%d\n",*v);
Could anybody knows the behaviour of void
and void*
in the above program codes?
A void * is just a pointer that Points to someting you don't know. So you can initialize ist. Even a void* isn't very useful, but it is a pointer and can be casted to a pointer of a specific type.
A void variable is "something you don't know" and so it can never be initialized and can not be declared.