Saturday, August 11, 2007

void and void *

* void
- NO INSTANCE of void data type, like "void a". The data type of void is abstract, like the abtract class in C++.
- void Usage: function return is void and function arguments are void

* "void *"
- The pointer of void * could be assigned by any type of pointer. No casting needed. However, it is not correct to assign the pointer of void * to the pointer of other data types. Casting needed.
- The pointer of void * could not perform arithmetic operations, like
void *p;
p++;    /* No increment is allowed on p */
- The pointer of void * could be used as an argument or return value of functions which accepts or return a pointer to any data type, respectively. For example,
void *memcpy(void *dst, void *src, size_t len);

No comments: