Sunday, January 22, 2012

Void Pointer vs Null Pointer

As on different systems size of a pointer can vary;Also size of pointer can vary depending upon the data type of the object to which it points.So C provides a pointer of type void which is a generic pointer.We can declare a void pointer as
void *vptr;
C does not permit the comparison of a pointer to type integer with a pointer to type character;but either of these can be compared to a void pointer

Question 1:
int main()
{
int a=10,*j;
void *k;
j=k=&a;
   j++; 
k++;
   printf("\n %u %u ",j,k);

Output:Compiler Error:Cannot increment a void pointer
Explanation:Void pointers are generic pointers and they can be used only when the
type  is not  known and as an  intermediate address storage  type.  No
pointer arithmetic can be done on it
and you cannot apply indirection
operator (*) on void pointers.

No comments:

Post a Comment